import sqlite3 as sqlite from weibo_api import get_api import datetime import db con = db.get_connection() cursor = con.cursor() api = get_api() class WeiboUser(): def __init__(self, user_id, scrn_name, name, foer_cnt, friend_cnt, desc, location, created_at, status_cnt, verified, scanned): self.user_id = user_id self.scrn_name = scrn_name self.name = name self.foer_cnt = foer_cnt self.friend_cnt = friend_cnt self.desc = desc self.location = location if isinstance(created_at, datetime.datetime): self.created_at = created_at.date() else: self.created_at = created_at self.status_cnt = status_cnt self.verified = verified self.scanned = scanned @classmethod def save_weibo_api(cls, w_api):
from weibo_api import get_api from weibo_user import WeiboUser from time import sleep a = get_api() TOP_100 = WeiboUser.get_top_100_by_foer() def relationship(): for id in TOP_100: not_foer = WeiboUser.get_top_not_pair(id) for foer in list(set(TOP_100)-set(not_foer)): WeiboUser.save_relationship(id, foer) def relationship_top(): for id in TOP_100: print 'analysis id', id sleep(1) for foer in TOP_100: if id != foer and not WeiboUser.get_relation(id, foer)\ and not WeiboUser.get_non_relation(id, foer): print 'analysis', id, 'and', foer, '...' try: e = a.exists_friendship(id,foer) except: continue if e.friends: print id, 'is followed by', foer, 'saving..' WeiboUser.save_relationship(id, foer) else: print id, 'is not followed by', foer, 'saving..'