def __init__(self):
     self.apitoken = config.get('Pushover', 'api_key')
     self.usertoken = config.get('Pushover', 'user_token')
     self.default_sound = None
     self.error_sound = None
     if config.has_option('Pushover', 'default sound'):
         self.default_sound = config.get('Pushover', 'default sound')
     if config.has_option('Pushover', 'error sound'):
         self.error_sound = config.get('Pushover', 'error sound')
     self.load_sounds()
示例#2
0
def setup():
    global http
    storage = Storage(config.get_storage_path(config.get('OAuth', 'storage')))
    credentials = storage.get()
    if credentials is None or credentials.invalid is True:
        flow = OAuth2WebServerFlow(
            client_id=config.get('OAuth', 'client_id'),
            client_secret=config.get('OAuth', 'client_secret'),
            scope=config.get('OAuth', 'scope'),
            user_agent=config.get('OAuth', 'user_agent'))
        credentials = run(flow, storage)
    if config.DEBUG and credentials.access_token_expired:
        print 'Credentials expired'
    http = credentials.authorize(http)
def load_stored_token():
    path = config.get_storage_path(config.get('Dropbox', 'storage'))
    if not os.path.isfile(path):
        return
    with open(path, 'r') as f:
        token = json.loads(f.read())
    return token
 def prepare_path(self, data):
     d = data.date
     basepath = config.get('Filesystem', 'basepath')
     basepath = os.path.expanduser(basepath)
     sep = os.sep
     path = "%s%s%d%s%d%s" % (basepath, sep, d.year, sep, d.month, sep)
     if not os.path.isdir(path):
         assert not os.path.exists(path)
         os.makedirs(path)
     return path
示例#5
0
from __future__ import division
from datetime import datetime
from latitude.config import config
from latitude.data import Data

import StringIO
import pytz
import xml.etree.ElementTree as ET

local_tz = config.get('KML', 'timezone')
local_tz = pytz.timezone(local_tz)


class KML(Data):
    extension = 'kml'

    def prepare(self):
        return self.build_document()

    def build_document(self):
        # build a tree structure
        kml = ET.Element("kml")
        kml.set('xmlns', "http://www.opengis.net/kml/2.2")
        kml.set('xmlns:atom', "http://www.w3.org/2005/Atom")
        kml.set('xmlns:kml', "http://www.opengis.net/kml/2.2")
        kml.set('xmlns:gx', "http://www.google.com/kml/ext/2.2")
        doc = ET.SubElement(kml, "Document")
        e = ET.SubElement(doc, "name")
        e.text = "Location history for %d"
        e = ET.SubElement(doc, "open")
        e.text = '1'
def store_token(token):
    data = {'key': token.key, 'secret': token.secret}
    path = config.get_storage_path(config.get('Dropbox', 'storage'))

    with open(path, 'w') as f:
        f.write(json.dumps(data))
from __future__ import absolute_import
from dropbox import client, session
from latitude.config import config

import json
import os

APP_KEY = config.get('Dropbox', 'app_key')
APP_SECRET = config.get('Dropbox', 'app_secret')
ACCESS_TYPE = config.get('Dropbox', 'access_type')


def get_client():
    sess = get_session()
    return client.DropboxClient(sess)


def load_stored_token():
    path = config.get_storage_path(config.get('Dropbox', 'storage'))
    if not os.path.isfile(path):
        return
    with open(path, 'r') as f:
        token = json.loads(f.read())
    return token


def store_token(token):
    data = {'key': token.key, 'secret': token.secret}
    path = config.get_storage_path(config.get('Dropbox', 'storage'))

    with open(path, 'w') as f:
 def setup_prowl(self):
     import prowlpy
     apikey = config.get('Prowl', 'api_key')
     self.prowl = prowlpy.Prowl(apikey)
            return  # hack
        if title == 'Failed' and self.error_sound:
            assert self.error_sound in self.sounds
            payload['sound'] = self.sounds[self.error_sound]
        elif self.default_sound:
            assert self.default_sound in self.sounds
            payload['sound'] = self.sounds[self.default_sound]
        if title != '':
            payload['title'] = title
        resp = requests.post('https://api.pushover.net/1/messages.json',
                        data=payload, headers=headers)
        resp.raise_for_status()


class TerminalNotification(Notification):
    name = 'terminal'

    def send(self, message, title=''):
        print "LatitudeExport: %s" % message

_notifiers = []
for c in [TerminalNotification, ProwlNotification, PushoverNotification]:
    if c.name in config.get('LatitudeExporter', 'notifications'):
        _notifiers.append(c())


def exception_notification(e):
    import traceback
    for n in _notifiers:
        n.send(traceback.format_exc(), 'Failed')