def getUserStatuses(self, screen_name): url = 'https://api.twitter.com/1.1/statuses/user_timeline.json' params = {'screen_name': screen_name, 'count': 100} psql = psql_save() req = self.api.get(url, params=params) if req.status_code == 200: req_text = json.loads(req.text) for status in req_text: try: psql.insert_status(status['user']['id'], status['user']['screen_name'], status['id'], status['text']) except: pass else: print("Error: %d at getUserInfo()" % req.status_code)
def getUserInfo(self, query_screen_name, ids): url = 'https://api.twitter.com/1.1/users/lookup.json' ids = np.array(ids).astype(str) psql = psql_save() for i in range(0, len(ids), 100): _ids = ','.join(ids[i:i + 100]) params = {'user_id': _ids} req = self.api.get(url, params=params) if req.status_code == 200: req_text = json.loads(req.text) for user in req_text: try: psql.insert_user_info(query_screen_name, user) except: print("Error: %d at getUserInfo()" % req.status_code) time.sleep(2 * random.uniform(0.5, 1.5))
df_cmx = pd.DataFrame(cmx_data, index=labels, columns=labels) plt.figure(figsize = (10,7)) sn.heatmap(df_cmx, annot=True) plt.show() def cos_sim(v1, v2): res = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2)) if np.isnan(res): return 0 else: return res # DBから取得 db = psql_save() rows = db.select_description_all() with open("lang.json","rb") as f: lang_list = json.load(f) # 正規表現の文字列作成 langnames = ["id"] lang_regexes = [] for lang in lang_list: lang_regex = '|'.join(lang_list[lang]) lang_regexes.append(lang_regex) langnames.append(lang) data = [] for row in rows: