def build_iconbar(twat, variables, quoted): bar = '\n<div class="iconbar">' ## anchor / next if not quoted: il = make_index_link(variables, ['page']) if not '?' in il: il += '?' else: il += '&' id = get_effective_twat_id(twat) il2 = il + 'find_next=%s'%id bar += '<a href="%s" name="%s">%s</a>'%(il2, id,'⏪') il2 = il + 'find=%s'%id bar += '<a href="%s" name="%s">%s</a>'%(il2, id,'⚓') il2 = il + 'find_prev=%s'%id bar += '<a href="%s" name="%s">%s</a>'%(il2, id,'⏩') ## twitter bar += ' <a target="_blank" href="https://api.twitter.com/1.1/statuses/retweets/%d.json" title="retweet">%s</a>' % (int(twat['id']), '🐦') ## wayback machine bar += ' <a target="_blank" href="https://web.archive.org/save/https://twitter.com/%s/status/%s" title="wayback">%s</a>' % (twat['user'], twat['id'], '♼') ## json file bar += ' <a target="_blank" href="%s">%s</a>' % (paths.get_user_json(twat['owner']), '💾') bar += '</div>\n' return bar
def load_watchlist(): global watchlist, wl_hash, has_keywords wl = [] for x in open(args.watchlist, 'r').readlines(): x = x.rstrip().lower() if x.startswith(';'): username = x[1:] disabled_users[username] = True else: username = x if username[0] == '#' and not has_keywords: has_keywords = True if not username[0] == '#' and not os.path.exists( paths.get_user_json(username)): new_accounts.append(username) if not os.path.exists(paths.get_user(username)): retry_makedirs(paths.get_user(username)) wl.append(username) newhash = hashlib.md5(''.join(wl)).hexdigest() if newhash != wl_hash: print('reloading watchlist') wl_hash = newhash watchlist = wl json_loads() if has_keywords and os.path.exists('users'): for file in os.listdir('users'): d = os.path.join('users', file) if os.path.isdir(d): load_user_json(file)
def load_user_json(user): tweet_cache[user] = dict() try: tweets[user] = json.loads(open(paths.get_user_json(user), 'r').read()) for i in xrange(len(tweets[user])): tweet_cache[user][get_effective_twat_id(tweets[user][i])] = True except: tweets[user] = []
def load_watchlist(): global watchlist, wl_hash wl = [] for x in open(args.watchlist, 'r').readlines(): x = x.rstrip() if x.startswith(';'): username = x[1:] disabled_users[username] = True else: username = x if not os.path.exists(paths.get_user_json(username)): new_accounts.append(username) if not os.path.exists(paths.get_user(username)): retry_makedirs(paths.get_user(username)) wl.append(username) newhash = hashlib.md5(''.join(wl)).hexdigest() if newhash != wl_hash: print('reloading watchlist') wl_hash = newhash watchlist = wl json_loads()
def write_user_tweets(user): fn = paths.get_user_json(user) content = json.dumps(tweets[user], sort_keys=True, indent=4) safe_write(fn, content)