Exemplo n.º 1
0
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,'&#9194;')
		il2 = il + 'find=%s'%id
		bar += '<a href="%s" name="%s">%s</a>'%(il2, id,'&#9875;')
		il2 = il + 'find_prev=%s'%id
		bar += '<a href="%s" name="%s">%s</a>'%(il2, id,'&#9193;')

	## twitter
	bar += '&nbsp;<a target="_blank" href="https://api.twitter.com/1.1/statuses/retweets/%d.json" title="retweet">%s</a>' % (int(twat['id']), '&#128038;')
	## wayback machine
	bar += '&nbsp;<a target="_blank" href="https://web.archive.org/save/https://twitter.com/%s/status/%s" title="wayback">%s</a>' % (twat['user'], twat['id'], '&#9852;')
	## json file
	bar += '&nbsp;<a target="_blank" href="%s">%s</a>' % (paths.get_user_json(twat['owner']), '&#128190;')

	bar += '</div>\n'
	return bar
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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] = []
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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)