示例#1
0
def main(symbols_file, output):
    symbols = _load_symbols(symbols_file)

    schema.init()
    dbsession = sessionmaker(bind=schema.engine)()

    if not output:
        fetch(symbols_file, symbols, dbsession)
    else:
        output2csv(symbols, dbsession)
示例#2
0
文件: am.py 项目: dgilman/atom_maker
def feed_cache(qs, flush=False):
   conn, c = schema.init()

   args = parse_qs(qs)
   args["cursor"] = c

   cache = c.execute("select ts, feed from cache where qs = ?", (args["cache_key"],)).fetchall()
   if len(cache) == 0 or (now - cache[0][0] > cache_length) or flush:
      rval = create_atom(get_feed(args))
      c.execute("replace into cache values (?, ?, ?)", (args["cache_key"], now, buffer(codecs.getencoder("zlib")(rval)[0])))
      conn.commit()
   else:
      rval = codecs.getdecoder("zlib")(cache[0][1])[0]
   conn.close()
   return rval
示例#3
0
#!/usr/bin/env python
import tweepy
from tweepy.error import TweepError

import schema

conn, c = schema.init()

print "Browse to this URL to authenticate with twitter."
handler = tweepy.auth.OAuthHandler('uX9gm761EDZqilGvwCd0bA', '1Ee8KV2vqZDzuM2uXWJwL8IsIVufxwkbWlEOKTA4', secure=True)

print handler.get_authorization_url()

while True:
   try:
      verify = raw_input("Activation code > ")
      token = handler.get_access_token(verifier=verify)
      break
   except TweepError:
      print "Try again."

api = tweepy.API(handler)
if not api.test():
   print "Sanity test failed"
   import sys
   sys.exit()

name = raw_input("What name do you want to give this token? ")

c.execute("insert into twitter_tokens (name, key, secret) values (?, ?, ?)", (name, token.key, token.secret))
conn.commit()