Refactor code to remove usage of Jsoup and Rssparser (#1888)

* Refactor code to remove usage of Jsoup and Rssparser

* Use current date for picture of the day
This commit is contained in:
Vivek Maskara 2018-09-11 21:14:41 +05:30 committed by GitHub
parent fc30f1b5ec
commit 86e849683a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 154 additions and 58 deletions

View file

@ -34,6 +34,7 @@ import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@ -51,6 +52,7 @@ import fr.free.nrw.commons.category.QueryContinue;
import fr.free.nrw.commons.notification.Notification;
import fr.free.nrw.commons.notification.NotificationUtils;
import fr.free.nrw.commons.utils.ContributionUtils;
import fr.free.nrw.commons.utils.DateUtils;
import in.yuvi.http.fluent.Http;
import io.reactivex.Observable;
import io.reactivex.Single;
@ -997,6 +999,44 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
}
/**
* The method returns the picture of the day
*
* @return Media object corresponding to the picture of the day
*/
@Override
@Nullable
public Single<Media> getPictureOfTheDay() {
return Single.fromCallable(() -> {
CustomApiResult apiResult = null;
try {
String template = "Template:Potd/" + DateUtils.getCurrentDate();
CustomMwApi.RequestBuilder requestBuilder = api.action("query")
.param("generator", "images")
.param("format", "xml")
.param("titles", template)
.param("prop", "imageinfo")
.param("iiprop", "url|extmetadata");
apiResult = requestBuilder.get();
} catch (IOException e) {
Timber.e("Failed to obtain searchCategories", e);
}
if (apiResult == null) {
return null;
}
CustomApiResult imageNode = apiResult.getNode("/api/query/pages/page");
if (imageNode == null
|| imageNode.getDocument() == null) {
return null;
}
return CategoryImageUtils.getMediaFromPage(imageNode.getDocument());
});
}
private Date parseMWDate(String mwDate) {
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH); // Assuming MW always gives me UTC
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

View file

@ -101,6 +101,8 @@ public interface MediaWikiApi {
Single<FeedbackResponse> getAchievements(String userName);
Single<Media> getPictureOfTheDay();
void logout();
interface ProgressListener {