Finnish Eniro search fixed. Changelog updated. Some modifications to control file.
authoreshe <jessehakanen@gmail.com>
Sun, 24 Oct 2010 11:40:35 +0000 (12:40 +0100)
committereshe <jessehakanen@gmail.com>
Sun, 24 Oct 2010 11:40:35 +0000 (12:40 +0100)
debian/changelog
debian/control
src/common/eniro.cpp
src/common/eniro.h

index b0f77aa..f74211d 100644 (file)
@@ -1,3 +1,9 @@
+jenirok (0.2-11) unstable; urgency=low
+
+  * Fixed Finnish Eniro search.
+
+ -- Jesse Hakanen <jessehakanen@gmail.com>  Sun, 24 Oct 2010 12:37:35 +0100
+
 jenirok (0.2-10) unstable; urgency=low
 
   * Changed search to retry automatically couple of times on failure.
index 4c10f85..8b82083 100644 (file)
@@ -10,16 +10,12 @@ Package: jenirok
 Architecture: any
 Depends: ${shlibs:Depends}, libqt4-sql-sqlite
 Description: Searches unknown callers' details automatically during call.
- Unknown callers' details are fetched automatically during call 
- using Eniro person search, 1881.no or Das Telefonbuch.
- Person search can also be done by using a gui application. 
- Jenirok is currently mainly usable for Finnish, Swedish, 
+ Unknown callers' details are fetched automatically during call using Eniro person search, 1881.no or Das Telefonbuch.
+ Person search can also be done by using a gui application. Jenirok is currently mainly usable for Finnish, Swedish, 
  Danish, Norwegian and German users.
 XB-Description-fi_FI: Hakee tuntemattoman soittajan tiedot Eniron henkilöhaulla.
- Jenirok hakee tuntemattoman soittajan tiedot
- automaattisesti Eniron henkilöhakua käyttämällä. 
- Haku onnistuu myös graafisen käyttöliittymän
- kautta.
+ Jenirok hakee tuntemattoman soittajan tiedot automaattisesti Eniron henkilöhakua käyttämällä. 
+ Haku onnistuu myös graafisen käyttöliittymän kautta.
 XSBC-Bugtracker: https://garage.maemo.org/tracker/?atid=5541&group_id=1530
 XB-Maemo-Display-Name: Jenirok
 XB-Maemo-Icon-26: 
index edffeed..85d9fc3 100644 (file)
@@ -45,7 +45,7 @@ namespace
     static const QString INVALID_LOGIN_STRING = "Invalid login details";
     static const QString TIMEOUT_STRING = "Request timed out";
     static const QString PERSON_REGEXP = "<td class=\"hTd2\">(.*)<b>(.*)</td>";
-    static const QString YELLOW_REGEXP = "<td class=\"hTd2\">(.*)<span class=\"gray\">(.*)</td>";
+    static const QString YELLOW_REGEXP = "<td class=\"hTd2\">(.*)<span class=\"gray\">(.*)</td>|<td class=\"hTd2\">(.*)<span class=\"bold\"\\}>(.*)</td>";
     static const QString SINGLE_REGEXP = "<div class=\"header\">(.*)</div>(.*)<div class=\"callRow\">(.*)(<div class=\"block\">|</p>(.*)<br/>|</p>(.*)<br />)";
     static const QString NUMBER_REGEXP = "<div class=\"callRow\">(.*)</div>";
     static const QString LOGIN_CHECK = "<input class=\"inpTxt\" id=\"loginformUsername\"";
@@ -150,7 +150,13 @@ void Eniro::search(SearchDetails const& details)
     QUrl url = createUrl(details.query, details.location);
     QString what;
 
-    if(loggedIn_ || site_ != FI)
+    // We must use full search instead of wap page because wap search is currently not
+    // working for persons
+    if(loggedIn_ && type == PERSONS && site_ == FI && getMaxResults() > 1)
+    {
+        what = "wp";
+    }
+    else if(loggedIn_ || site_ != FI)
     {
         switch(type)
         {
@@ -178,6 +184,8 @@ void Eniro::search(SearchDetails const& details)
     http_.setHost(url.host(), url.port(80));
     int id = http_.get(url.encodedPath() + '?' + url.encodedQuery());
 
+    //qDebug() << "Url: " << url.host() << url.encodedPath() << "?" << url.encodedQuery();
+
     QVector <Source::Result> results;
 
     // Store search data for later identification
@@ -279,6 +287,13 @@ void Eniro::loadResults(int id, QString const& httpData)
 {
     searchMap::iterator it = pendingSearches_.find(id);
 
+    // Finnish person search is not working in wap mode so we have to use different type of loading
+    if(getMaxResults() > 1 && loggedIn_ && site_ == FI && it.value()->details.type == PERSONS)
+    {
+        loadFinnishPersonResults(id, httpData);
+        return;
+    }
+
     QRegExp rx("((" + YELLOW_REGEXP + ")|(" + PERSON_REGEXP + ")|(" + SINGLE_REGEXP + "))");
     rx.setMinimal(true);
 
@@ -443,6 +458,102 @@ void Eniro::loadResults(int id, QString const& httpData)
     }
 }
 
+void Eniro::loadFinnishPersonResults(int id, QString const& httpData)
+{
+    searchMap::iterator it = pendingSearches_.find(id);
+
+    static QRegExp rx("<div id=\"hit_(.*)<p class=\"adLinks\">");
+    static QRegExp name("<a class=\"fn expand\" href=\"#\">(.*)</a>");
+    static QRegExp number("<!-- sphoneid(.*)-->(.*)<!--");
+    static QRegExp street("<span class=\"street-address\">(.*)</span>");
+    static QRegExp zipCode("<span class=\"postal-code\">(.*)</span>");
+    static QRegExp city("<span class=\"locality\">(.*)</span>");
+    rx.setMinimal(true);
+    name.setMinimal(true);
+    number.setMinimal(true);
+    street.setMinimal(true);
+    zipCode.setMinimal(true);
+    city.setMinimal(true);
+
+    int pos = 0;
+
+    unsigned int maxResults = getMaxResults();
+    unsigned int foundResults = 0;
+
+    while((pos = rx.indexIn(httpData, pos)) != -1)
+    {
+        pos += rx.matchedLength();
+
+        QString data = rx.cap(0);
+
+        Result result;
+
+        if(name.indexIn(data) != -1)
+        {
+            result.name = name.cap(1);
+        }
+        else
+        {
+            continue;
+        }
+
+        if(number.indexIn(data) != -1)
+        {
+            result.number = number.cap(2);
+        }
+
+        if(street.indexIn(data) != -1)
+        {
+            result.street = street.cap(1);
+        }
+
+        QString cityStr;
+
+        if(zipCode.indexIn(data) != -1)
+        {
+            cityStr = zipCode.cap(1) + " ";
+        }
+
+        if(city.indexIn(data) != -1)
+        {
+            cityStr += city.cap(1);
+        }
+
+        result.city = cityStr;
+
+        result.name = cleanUpString(result.name);
+        result.street = cleanUpString(result.street);
+        result.number = cleanUpNumber(result.number);
+        result.city = cleanUpString(result.city);
+        result.country = "Finland";
+
+        it.value()->results.push_back(result);
+        emit resultAvailable(result, it.value()->details);
+
+        foundResults++;
+
+        if(foundResults >= maxResults)
+        {
+            break;
+        }
+
+    }
+
+    emitRequestFinished(it.key(), it.value(), false);
+
+}
+
+QString& Eniro::cleanUpString(QString& str)
+{
+    str = htmlEntityDecode(str);
+    str = str.toLower();
+    str = str.trimmed();
+    static QRegExp cleaner("(\r\n|\n|\t| )+");
+    str = str.replace(cleaner, " ");
+    str = ucFirst(str);
+    return str;
+}
+
 // Loads phone number from html source
 void Eniro::loadNumber(int id, QString const& result)
 {
index fbba9f4..c1aab83 100644 (file)
@@ -81,11 +81,13 @@ private:
     virtual void handleHttpError(int id);
     QUrl createUrl(QString const& query, QString const& location);
     void loadResults(int id, QString const& data);
+    void loadFinnishPersonResults(int id, QString const& data);
     void loadNumber(int id, QString const& data);
     void getNumberForResult(int id, int index, SearchDetails const& details);
     void emitRequestFinished(int key, SearchData* data, bool error);
     void timerEvent(QTimerEvent *t);
     bool isStreet(QString const& str);
+    QString& cleanUpString(QString& str);
 
     Site site_;
     bool loggedIn_;