Esempio n. 1
0
def do_flush_key(key):
    spider_log.info("正在刷新Key ID:{}".format(key.id))
    t = Tumblpy(key.ConsumerKey, key.ConsumerSecret)
    auth_props = t.get_authentication_tokens()
    key.Token = auth_props.get("oauth_token")
    key.TokenSecret = auth_props.get("oauth_token_secret")
    spider_log.info("请打开下面的链接执行授权")
    spider_log.info(auth_props.get("auth_url"))
    key.UpdateTime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    t.client.close()
    session.commit()
    spider_log.info("刷新Key ID:{} 完成".format(key.id))
Esempio n. 2
0
def add_student():
    if (request.method == 'POST'):
        try:
            name = request.form['name']
            roll_no = request.form['roll']
            student = Student_Details(name=name, roll_no=roll_no)
            session.add(student)
            session.commit()
            return 'You are successfully registered.'
        except KeyError as k:
            return 'No arguments found in post request'

    else:
        return render_template('student_form.html')
Esempio n. 3
0
 def do():
     spider_log.info("开始获取博客信息!")
     blogs = load_all_blog()
     spider_log.info("加载Blog列表完成!")
     for blog in blogs:
         try:
             t = Tumblpy(self.key.ConsumerKey, self.key.ConsumerSecret)
             resp = t.get('info', blog_url=urlparse(blog.url).netloc)
             b = resp.get("blog")
             t.client.close()
             blog.name = b.get("name")
             blog.url = b.get("url")
             blog.posts = b.get("posts")
             spider_log.info("BlogId:{} 已更新".format(blog.id))
         except TumblpyRateLimitError:
             spider_log.info("Key达到上限,本线程退出")
         except TumblpyError as e:
             if e.error_code == 404:
                 mark_dead_blog(blog)
         finally:
             session.commit()
     session.remove()
Esempio n. 4
0
def commit():
    session.commit()
Esempio n. 5
0
 def wrapper(*args, **kwargs):
     k = session.query(Key).with_lockmode('update').get(key.id)
     k.UseTimes += 1
     session.commit()
     return func(*args, **kwargs)
Esempio n. 6
0
def add_item(item):
    session.add(item)
    session.commit()
Esempio n. 7
0
    def wrapper(*args, **kwargs):
        b = session.query(Blog).with_lockmode('update').get(args[0].blog_id)
        b.loaded_video += 1
        session.commit()

        return func(*args, **kwargs)
Esempio n. 8
0
def mark_dead_blog(blog):
    b = session.query(Blog).with_lockmode('update').get(blog.id)
    b.alive = 0
    session.commit()
Esempio n. 9
0
 def fail_callback(self):
     self.item.file_path = "#error"
     session.commit()
Esempio n. 10
0
 def success_callback(self, file_path):
     self.item.file_path = file_path
     session.commit()