[Suggestion] Auto detect location on first run

Asked by Alessio L. on 2011-05-09

I suggest to add a new feature:

the auto detection of the current location on the first run.

One implementation can be (only for the first run or if there are no settings yet) :

/usr/bin/indicator-weather

   1) Check for internet connection, skip to (4) if none;
   2) Run a script for retrieve necessary informations (my version at the bottom of the page);
   3) If (2), store informations in the program database, else, skip to (4);
   4) Run program

POSSIBLE SCRIPT:

#! /usr/bin/env python

import urllib, urllib2

def TryConnection(temprequest):

    try:

        response = urllib2.urlopen(temprequest)
    except urllib2.HTTPError, e: # No internet connection

        print 'The server couldn\'t fulfill the request.\nError code: ', e.code
        return -1
    except urllib2.URLError, e: # No internet connection

        print 'We failed to reach the server.\nReason: ', e.reason
        return -1
    else: # Internet connection available

        temp = response.read()
        response.close()
        return temp

url = "http://infosniper.net" # Information website

req = urllib2.Request(url, data = None)

pageBuffer = TryConnection(req) # Validate request

if not pageBuffer == -1:

    var = []

    for line in pageBuffer.split('\n'):
        if 'content-td2' in line:

            temp = line.split('content-td2\">')[1]
            if ' <' in temp:

                temp = temp.split(' <')[0]
            else:

                temp = temp.split('<')[0]

            var.append(temp)

    #print var # Test
    print "%s, %s" % (var[1], var[9]) # City, Country
else:

    print 'Couldn\' retrieve webpage'

Question information

Language:
English Edit question
Status:
Answered
For:
Weather Indicator Edit question
Assignee:
No assignee Edit question
Last query:
2011-05-09
Last reply:
2011-05-09
Panagiotis Skintzos (ph7) said : #1

Hi Alesio,

we're gonna add location autodetection (and follow-up) in the next version (foggy/series3)

Panagiotis Skintzos (ph7) said : #2

See related linked bug

Can you help with this problem?

Provide an answer of your own, or ask Alessio L. for more information if necessary.

To post a message you must log in.