def auth(self, pin): try: token = self.hdl.get_access_token(pin) self.api = API(self.hdl) except: raise Exception("OAuth Failed!") self.token.update(dict(key=token.key, secret=token.secret)) log("Access Token is: " + str(self.token)) with open(config.TOKEN_FILE, "w") as f: pickle.dump(self.token, f) log("pickle saved success!")
def __init__(self): self.hdl = OAuthHandler(config.APP_KEY, config.APP_SECRET) self.api = None self.token = {} try: with open(config.TOKEN_FILE) as f: self.token = pickle.load(f) log("token init success!") log("Access Token is: " + str(self.token)) self.hdl.setToken( self.token["key"], self.token["secret"] ) self.api = API(self.hdl) except: log("Haven't Authorizationed!") print "Authorization URL: %s" % self.get_auth_url() pin = raw_input("PIN: ") self.auth(pin)
""" 启动脚本 start 启动 crontab stop 删除 crontab """ from Helper import log # 获取启动参数 import sys, os try: if sys.argv[1] == 'stop': os.system("crontab -r") log("rm all the crontab") exit(0) except IndexError: pass except SystemExit: raise cnt_path = os.path.dirname(os.getcwd() + "/" + sys.argv[0]) SPIDER_FILE = "Spider.py" POSTER_FILE = "Poster.py" SPIDER_LOG = "spider.log" POSTER_LOG = "poster.log" SPIDER_CRON = "*/1 * * * * cd %s && python %s>>%s\n" % (cnt_path, SPIDER_FILE, SPIDER_LOG) POSTER_CRON = "*/1 * * * * cd %s && python %s>>%s\n" % (cnt_path, POSTER_FILE, POSTER_LOG)
#-*- coding: utf-8 -*- """ 启动脚本 start 启动 crontab stop 删除 crontab """ from Helper import log # 获取启动参数 import sys, os try: if sys.argv[1] == 'stop': os.system("crontab -r") log("rm all the crontab") exit(0) except IndexError: pass except SystemExit: raise cnt_path = os.path.dirname(os.getcwd() + "/" + sys.argv[0]) SPIDER_FILE = "Spider.py" POSTER_FILE = "Poster.py" SPIDER_LOG = "spider.log" POSTER_LOG = "poster.log" SPIDER_CRON = "*/1 * * * * cd %s && python %s>>%s\n" % (cnt_path, SPIDER_FILE, SPIDER_LOG)