mirror of
https://github.com/akaessens/NoFbEventScraper
synced 2025-02-16 11:31:15 +01:00
improve high-res image url scraping
This commit is contained in:
parent
bb1e7579d8
commit
320d1787aa
@ -52,7 +52,8 @@ public class FbEvent {
|
||||
*/
|
||||
static String dateTimeToString(Date date) {
|
||||
try {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm z", Locale.getDefault());
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm z",
|
||||
Locale.getDefault());
|
||||
return formatter.format(date);
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
|
@ -64,7 +64,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
if (matcher.find()) {
|
||||
|
||||
String url_prefix = "https://m.";
|
||||
if (main != null){
|
||||
if (main != null) {
|
||||
SharedPreferences shared_prefs = PreferenceManager.getDefaultSharedPreferences(main.get());
|
||||
url_prefix = shared_prefs.getString("url_preference", url_prefix);
|
||||
}
|
||||
@ -84,6 +84,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
/**
|
||||
* Strips the event location from the json string.
|
||||
* This can be a name only or a complete postal address.
|
||||
*
|
||||
* @param location_json JSON formatted string
|
||||
* @return String representation of the location.
|
||||
*/
|
||||
@ -164,6 +165,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
/**
|
||||
* Read a single field from a JSONObject
|
||||
*
|
||||
* @param reader JSONObject to read from
|
||||
* @param field Which field to read
|
||||
* @return String of the value of the field or empty string
|
||||
@ -180,6 +182,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
/**
|
||||
* Started by scraper.execute().
|
||||
* Gets the HTML doc from the input string and scrapes the event information from it.
|
||||
*
|
||||
* @param voids
|
||||
* @return
|
||||
*/
|
||||
@ -212,14 +215,14 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
try {
|
||||
// possibly get higher res image from event header
|
||||
image_url = document.getElementsByClass("scaledImageFitWidth")
|
||||
image_url = document.select("img[class*=scaledImageFit]")
|
||||
.first().attr("src");
|
||||
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
event = new FbEvent(url, name,start_date, end_date, description, location, image_url);
|
||||
event = new FbEvent(url, name, start_date, end_date, description, location, image_url);
|
||||
|
||||
|
||||
} catch (URISyntaxException | MalformedURLException e) {
|
||||
@ -247,6 +250,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
||||
/**
|
||||
* When scraping is finished, main activity will be updated.
|
||||
* If an error occurred, main activity is given an error string.
|
||||
*
|
||||
* @param aVoid
|
||||
*/
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
|
@ -331,7 +331,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
|
||||
if(menu instanceof MenuBuilder){
|
||||
if (menu instanceof MenuBuilder) {
|
||||
MenuBuilder m = (MenuBuilder) menu;
|
||||
//noinspection RestrictedApi
|
||||
m.setOptionalIconsVisible(true);
|
||||
|
@ -60,7 +60,8 @@
|
||||
app:layout_anchorGravity="bottom|end"
|
||||
app:icon="@drawable/ic_content_paste"
|
||||
android:text="@android:string/paste"
|
||||
android:tooltipText="@string/tooltip_paste"/>
|
||||
android:tooltipText="@string/tooltip_paste"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
|
||||
<include layout="@layout/content_main" />
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user