Ejemplo n.º 1
0
def say():
    s = request.environ.get('beaker.session')
    access_token = s.get('access_token', '')
    if not access_token:
        toggle_notice('还未登录, <a href="/auth"><img src="/static/login240.png" /></a> ')
        redirect('/')
    if not check_formhash():
        abort(403, 'how you get here?')

    o = lib.get_user_api(access_token)
    
    word = request.POST.get('word', '')
    word = " ".join(word.split())
    wordlen = len(lib.mb_code(word, 'utf-8').decode('utf-8'))
    toweiqun = request.POST.get('toweiqun', '')
    if wordlen == 0 or wordlen > 140:
	abort(403, 'invalid status')
		
    try:
        api = lib.get_api()
        api.update_status(word)
        toggle_notice('小纸条已经丢进树洞')
        if toweiqun == 'on':
            lib.appendto(
                lib.get_timed_path('toweiqun'),
                word + "\n",
            )
        return {
            'uid': s.get('uid', ''),
            'name': s.get('name',''),
            'notice': toggle_notice(),
            'formhash': set_formhash(),
        }
    except Exception, e:
        return "error: " + str(e)
Ejemplo n.º 2
0
import lib
from pandas.io.json import json_normalize
import pandas as pd
import time
import re
from datetime import datetime, timedelta

cred = lib.cred_emcanalyticsteam

api_access = lib.get_api()

def convert_insight_data(raw):
    val = []
    for i in raw:
        val.append({i['name'] : str(i['values'][0]['value'])})
    return val

def get_user_media2(params, pagingUrl = ''):
    """ Get users media

    	API Endpoint:
    		https://graph.facebook.com/{graph-api-version}/{ig-user-id}/media?fields={fields}&access_token={access-token}
    	Returns:
    		object: data from the endpoint
    """
    endpointParams = dict()
    endpointParams['fields'] = 'id,media_type,username,media_url,permalink,timestamp,caption,like_count,comments_count,insights.metric(reach,impressions,saved)'
    endpointParams['access_token'] = api_access
    if ('' == pagingUrl) :
        url = params['endpoint_base'] + params['instagram_account_id'] + '/media'
    else:
Ejemplo n.º 3
0
from time import sleep, time
import os

def get_n():
    path = lib.get_timed_path('toweiqun') + "-n"
    if os.path.exists(path):
        return int(lib.readfrom(path))
    else:
        lib.writeto(path, "0")
        return 0

def set_n(n):
    path = lib.get_timed_path('toweiqun') + "-n"
    lib.writeto(path, str(n))

o = lib.get_api()


sina = Sina(conf.username, conf.password)
prevtime = 0

while True:
    newtime = int(time())
    if newtime - prevtime >= 3600 * 3:
        try:
            sina.login()
            print newtime, sina.cookies
            prevtime = newtime
        except: pass
    
Ejemplo n.º 4
0
def pub2qq(status):
    from lib import get_api
    o = get_api()
    o.tweet.add(status)
Ejemplo n.º 5
0
import os
import time
import lib
import tweepy
import json

try:
    os.mkdir("data")
except:
    pass

while True:
    try:
        api = lib.get_api()
        id = int(time.time() * 1000)
        old_id = lib.old_id(id)
        if old_id != None:
            old_data = lib.Data.load(old_id)
            users = list(old_data.followers | old_data.friends
                         | old_data.outgoing)
            actives = []
            for x in lib.list_split(100, users):
                actives.extend([x.id for x in api.lookup_users(user_ids=x)])
        else:
            actives = []

        data = lib.Data(
            id=id,
            friends=list(tweepy.Cursor(api.friends_ids, count=5000).items()),
            followers=list(
                tweepy.Cursor(api.followers_ids, count=5000).items()),
Ejemplo n.º 6
0
def pub2sina(status):
    from lib import get_api
    o = get_api()
    o.update_status(status)
Ejemplo n.º 7
0
def get_sina_status():
    from lib import get_api
    o = get_api()
    print dir(o)
    return o.user_timeline(count=10, page=1)