mirror of
https://github.com/akaessens/NoFbEventScraper
synced 2025-02-17 20:10:37 +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) {
|
static String dateTimeToString(Date date) {
|
||||||
try {
|
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);
|
return formatter.format(date);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -64,7 +64,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
|||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
|
||||||
String url_prefix = "https://m.";
|
String url_prefix = "https://m.";
|
||||||
if (main != null){
|
if (main != null) {
|
||||||
SharedPreferences shared_prefs = PreferenceManager.getDefaultSharedPreferences(main.get());
|
SharedPreferences shared_prefs = PreferenceManager.getDefaultSharedPreferences(main.get());
|
||||||
url_prefix = shared_prefs.getString("url_preference", url_prefix);
|
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.
|
* Strips the event location from the json string.
|
||||||
* This can be a name only or a complete postal address.
|
* This can be a name only or a complete postal address.
|
||||||
|
*
|
||||||
* @param location_json JSON formatted string
|
* @param location_json JSON formatted string
|
||||||
* @return String representation of the location.
|
* @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
|
* Read a single field from a JSONObject
|
||||||
|
*
|
||||||
* @param reader JSONObject to read from
|
* @param reader JSONObject to read from
|
||||||
* @param field Which field to read
|
* @param field Which field to read
|
||||||
* @return String of the value of the field or empty string
|
* @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().
|
* Started by scraper.execute().
|
||||||
* Gets the HTML doc from the input string and scrapes the event information from it.
|
* Gets the HTML doc from the input string and scrapes the event information from it.
|
||||||
|
*
|
||||||
* @param voids
|
* @param voids
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -212,14 +215,14 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// possibly get higher res image from event header
|
// possibly get higher res image from event header
|
||||||
image_url = document.getElementsByClass("scaledImageFitWidth")
|
image_url = document.select("img[class*=scaledImageFit]")
|
||||||
.first().attr("src");
|
.first().attr("src");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// 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) {
|
} 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.
|
* When scraping is finished, main activity will be updated.
|
||||||
* If an error occurred, main activity is given an error string.
|
* If an error occurred, main activity is given an error string.
|
||||||
|
*
|
||||||
* @param aVoid
|
* @param aVoid
|
||||||
*/
|
*/
|
||||||
protected void onPostExecute(Void 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.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||||
|
|
||||||
if(menu instanceof MenuBuilder){
|
if (menu instanceof MenuBuilder) {
|
||||||
MenuBuilder m = (MenuBuilder) menu;
|
MenuBuilder m = (MenuBuilder) menu;
|
||||||
//noinspection RestrictedApi
|
//noinspection RestrictedApi
|
||||||
m.setOptionalIconsVisible(true);
|
m.setOptionalIconsVisible(true);
|
||||||
|
@ -60,7 +60,8 @@
|
|||||||
app:layout_anchorGravity="bottom|end"
|
app:layout_anchorGravity="bottom|end"
|
||||||
app:icon="@drawable/ic_content_paste"
|
app:icon="@drawable/ic_content_paste"
|
||||||
android:text="@android:string/paste"
|
android:text="@android:string/paste"
|
||||||
android:tooltipText="@string/tooltip_paste"/>
|
android:tooltipText="@string/tooltip_paste"
|
||||||
|
tools:ignore="UnusedAttribute" />
|
||||||
|
|
||||||
<include layout="@layout/content_main" />
|
<include layout="@layout/content_main" />
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user