use of com.ferg.awfulapp.util.AwfulError in project Awful.apk by Awful.
the class Reply method getReplyData.
public static final ContentValues getReplyData(Document data, ContentValues results) throws AwfulError {
try {
Element formKey = data.getElementsByAttributeValue("name", "formkey").first();
Element formCookie = data.getElementsByAttributeValue("name", "form_cookie").first();
results.put(AwfulPost.FORM_KEY, formKey.val());
results.put(AwfulPost.FORM_COOKIE, formCookie.val());
} catch (Exception e) {
throw new AwfulError("Failed to load reply");
}
return results;
}
use of com.ferg.awfulapp.util.AwfulError in project Awful.apk by Awful.
the class AwfulMessage method processMessageList.
public static void processMessageList(ContentResolver contentInterface, Document data, int folder) throws AwfulError {
ArrayList<ContentValues> msgList = new ArrayList<ContentValues>();
/**
*METHOD One: Parse PM links. Easy, but only contains id+title.*
*/
/*TagNode[] messagesParent = data.getElementsByAttValue("name", "form", true, true);
if(messagesParent.length > 0){
TagNode[] messages = messagesParent[0].getElementsByName("a", true);
for(TagNode msg : messages){
String href = msg.getAttributeByName("href");
if(href != null){
AwfulMessage pm = new AwfulMessage(Integer.parseInt(href.replaceAll("\\D", "")));
pm.mTitle = msg.getText().toString();
pm.mAuthor = "";
msgList.add(pm);
}
}
}else{
Log.e("AwfulMessage","Failed to parse message parent");
return null;//we'll use this to show that the load failed. i am still lazy.
}*/
/**
*METHOD Two: Parse table structure, hard and quick to break.*
*/
Elements messagesParent = data.getElementsByAttributeValue("name", "form");
if (messagesParent.size() > 0) {
Elements messages = messagesParent.first().getElementsByTag("tr");
for (Element msg : messages) {
if (msg == messages.get(0)) {
continue;
}
ContentValues pm = new ContentValues();
// fuck i hate scraping shit.
// no usable identifiers on the PM list, no easy method to find author/post date.
// this will break if they change the display structure.
Elements row = msg.getElementsByTag("td");
if (row != null && row.size() > 4) {
// TODO abandon hope, all ye who enter
// row[0] - icon, newpm.gif - sublevel
// row[1] - post icon TODO if we ever add icon support - sublevel
// row[2] - pm subject/link - sublevel
// row[3] - sender
// row[4] - date
Element href = row.get(2).getElementsByTag("a").first();
pm.put(ID, Integer.parseInt(href.attr("href").replaceAll("\\D", "")));
pm.put(TITLE, href.text());
Element icon = row.get(1).getElementsByTag("img").first();
if (icon == null) {
pm.put(ICON, "");
} else {
pm.put(ICON, icon.attr("src"));
}
pm.put(AUTHOR, row.get(3).text());
pm.put(DATE, row.get(4).text());
pm.put(CONTENT, " ");
if (row.first().getElementsByTag("img").first().attr("src").endsWith("newpm.gif")) {
pm.put(UNREAD, 1);
} else if (row.first().getElementsByTag("img").first().attr("src").endsWith("pmreplied.gif")) {
pm.put(UNREAD, 2);
} else {
pm.put(UNREAD, 0);
}
pm.put(FOLDER, folder);
msgList.add(pm);
}
}
} else {
throw new AwfulError("Failed to parse message parent");
}
contentInterface.bulkInsert(CONTENT_URI, msgList.toArray(new ContentValues[msgList.size()]));
}
use of com.ferg.awfulapp.util.AwfulError in project Awful.apk by Awful.
the class ProfileRequest method handleResponse.
@Override
protected Void handleResponse(Document doc) throws AwfulError {
Element formkey = doc.getElementsByAttributeValue("name", "formkey").first();
if (formkey != null) {
try {
getPreferences().setPreference(Keys.IGNORE_FORMKEY, formkey.val());
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new AwfulError("Profile page did not load");
}
Element title = doc.getElementsByClass("title").first();
if (null != title) {
String userTitle = "";
Elements titleTags = title.getAllElements();
for (Element tag : titleTags) {
String tagName = tag.tagName();
if ("br".equals(tagName)) {
break;
} else if ("img".equals(tagName)) {
userTitle = tag.attr("src");
break;
}
}
try {
getPreferences().setPreference(Keys.USER_TITLE, userTitle);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
Aggregations