Esempio n. 1
0
def debug(message):
    """prints debug message to logfile"""
    conf=libconfig.config()
    try:
        logfile = open(conf.debuglog, 'a')
    except Exception, e:
        quit('no debuglog path specified, that is required for now.',1)
Esempio n. 2
0
def unfollow(entity,lastid=""):
    """unfollow entity
    get ent['id'] first from followers and unfollow that id
    NOT WORKING
    """
    conf=config.config()
    app = login.login()
    if lastid:
        debug('unfollow: Have lastid: %s'%(lastid))
        getf = app.getFollowers(since_id=lastid)
    else:
        debug('unfollow: Have NO lastid')
        getf = app.getFollowers()
    for ent in getf:
        lastid=ent['id']
        debug('lastid in loop = %s'%(lastid))
        if ent['entity']==entity:
            debug('found entity match: %s and %s'%(ent['entity'],entity))
            try:
                app.unfollow(ent['id'])
                debug('unfollowed: %s'%(entity))
                return True
            except Exception, e:
                debug('error unfollowing: %s' % (entity))
                debug(e)
                return False
        else:
            debug('%s is not the same as %s'%(ent['entity'],entity))
Esempio n. 3
0
def getstatusfromfile():
    """get posts from datastorage returns list of posts"""
    statuslist = []
    conf=libconfig.config()
    try:
        filelines = open(conf.datastore+'status', 'r').readlines()
    except Exception, e:
        return statuslist
Esempio n. 4
0
def follow(entity):
    """follow entity"""
    conf=config.config()
    app = login.login()
    f=app.follow(str(entity))
    if f:
        return True
    else:
        retstring = "Could not follow %s" % (entity,e)
        return retstring
Esempio n. 5
0
def login(test=""):
    """login to your server"""
    """TODO: error handling failed login does not work in tentapp.py"""
    """      and login is not really used until fetching post"""
    """      so maybe change sanitycheck to include fetching one post"""

    
    conf=config.config()
    entityUrl=conf.entityUrl
    keystore=conf.keystore
    app = tentapp.TentApp(entityUrl)

    app.appDetails = {
        'name': 'Tentog',
        'description': 'trying to be a pale shadow of mutt, and irssi, but done in python, err, well a practical curses to tent',
        'url': 'http://zzzzexample.com',
        'icon': 'http://zzzzexample.com/icon.png',
        'oauthCallbackURL': 'http://zzzzexample.com/oauthcallback',
        'postNotificationUrl': None,
        }

    keyStore = tentapp.KeyStore(keystore)
    app.keys = keyStore.get(entityUrl, {})

    if not app.hasRegistrationKeys():
        app.register()
        keyStore.save(entityUrl, app.keys)

    if not app.hasPermanentKeys():
        approvalURL = app.getUserApprovalURL()
        a=raw_input("Tentog can't find your keystore as specified in your config file.\nDo you wish to create it now? (Y/n) ")
        if a in ['Y','y','']:
            print "\nPlease go to this url to register Tentog:\n"
            print approvalURL
            print 
            print 'After registration find this code in your url:'
            print 'http://zzzzexample.com/oauthcallback?code=15673b7718651a4dd53dc7defc88759e&state=ahyKV...'
            print '                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
            print 'Enter that code here:'
            code = raw_input('> ')
            print '-----------'
            app.getPermanentKeys(code)
            keyStore.save(entityUrl, app.keys)

    if test:
        return app.getProfile()

    if app.hasPermanentKeys():
        return app
Esempio n. 6
0
def sendpost(message):
    """send post to server"""
    conf = libconfig.config()
    app = liblogin.login()
    post = {
        # add split message if > 256 char
        "type": "https://tent.io/types/post/status/v0.1.0",
        "published_at": int(time.time()),
        "permissions": {
            # add private as option
            "public": True
        },
        # this should be read from config file
        "licenses": [""],
        "app": {"name": "Tentog"},
        "content": {"text": message},
    }
    try:
        app.putPost(post)
    except Exception, e:
        libfunc.debug("something went wrong posting: \n%s" % (message))
        libfunc.debug(e)
Esempio n. 7
0
def sanitycheck():
    """pre-flight sanity check"""
    try:
        conf=libconfig.config()
    except Exception, e:
        print e
Esempio n. 8
0
 def __init__(self):
     conf = libconfig.config()
     posts = app.getPosts(mentioned_entity=conf.entityUrl())
     posts.sort(key=lambda p: p["published_at"])
     return posts