예제 #1
0
def find_tweet_page(all_tweets, twid, offset):
	for i in xrange(0, len(all_tweets)):
		if get_effective_twat_id(all_tweets[i]) == twid:
			if i + offset >= 0 and i < len(all_tweets):
				i += offset
			return int(i / args.tpp), get_effective_twat_id(all_tweets[i])
	return 0
예제 #2
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
예제 #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] = []
예제 #4
0
def sort_tweets_func(x, y):
	# somewhere in 2017, the numbering scheme of twitter changed
	# that's a pity because the twat id is the most accurate
	# sorting indicator, so we use it on all tweets > 2018
	timestamp_2018 = 1514764800 #01/01/2018
	if x['time'] > timestamp_2018 and y['time'] > timestamp_2018:
		t1 = int(get_effective_twat_id(x))
		t2 = int(get_effective_twat_id(y))
		if t1 == t2: return 0
		elif t1 > t2: return 1
		else: return -1
	else:
		t1 = retweet_time(x) if 'rid' in x else x["time"]
		t2 = retweet_time(y) if 'rid' in y else y["time"]
		if t1 == t2: return 0
		elif t1 > t2: return 1
		else: return -1
예제 #5
0
def htmlize_twat(twat, variables, quoted=False):
	tw = '<div class="twat-container">'
	tweet_pic = None
	retweet_pic = None

	if not 'rid' in twat:
		retweet_str = ""
		if paths.has_profile_pic(twat['owner']): tweet_pic = paths.get_profile_pic(twat['owner'])

	else:
		if paths.has_profile_pic(twat['user']): tweet_pic = paths.get_profile_pic(twat['user'])
		else: tweet_pic = "data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs="

		if paths.has_profile_pic(twat['owner']): retweet_pic = paths.get_profile_pic(twat['owner'])

		retweet_str = " (RT %s<a target='_blank' href='https://twitter.com/%s/status/%s'>%s</a>)" % \
		(user_at_link(twat['user']), twat['user'], twat['id'], twat['user'])

	if tweet_pic: tw += '<div class="profile_picture"><img width="100%%" height="100%%" src="%s"></div>' % tweet_pic
	if retweet_pic: tw += '<div class="profile_picture_retweet"><img width="100%%" height="100%%" src="%s"></div>' % retweet_pic

	user_str =  user_at_link(twat["owner"])
	user_str += "<a target='_blank' href='https://twitter.com/%s/status/%s'>%s</a>%s" % \
	(twat["owner"], get_effective_twat_id(twat), twat["owner"], retweet_str)


	tw += '\n<div class="twat-title">'

	## add icon bar
	if args.iconbar: tw += build_iconbar(twat, variables, quoted)

	time_str = 'unknown' if twat["time"] == 0 else format_time(twat["time"])
	tw += '%s&nbsp;-&nbsp;%s' % (user_str, time_str)

	tw += '\n</div>\n'

	## replace urls in twats
	twat['text'] = replace_url_in_twat(twat, args=args)
	## strip html ?
	if args.nohtml: twat['text']= strip_tags(twat['text'])

	tw += '<p class="twat-text">%s</p>\n' % (replace_twat_text(twat['text']))

	if 'curl' in twat and args.iframe > 0:
		user = twat['user'].lower()
		ifu = paths.get_user(user) + '/%s-%s' % (twat['id'], "card.html")
		if (not 'c' in args.mirror) or (not file_exists(ifu)):
			ifu = twat['curl']
		tw += '<span class="twat-iframe"><iframe src="%s"></iframe></span>\n'%ifu

	if 'images' in twat:
		tw += '<p class="twat-image">'
		if len(twat['images']) > 1: wdth = (100/len(twat['images'])) - 1
		else: wdth = 100

		for i in twat['images']:
			if args.images <= 0:
				tw += '<a href="%s">%s</a>'%(i, i)
			else:
				img_path = paths.get_user(twat['user']) + "/%s-%s" % (twat['id'], i.split('/')[-1])
				if not file_exists(img_path): img_path = i
				span_or_div = "span"
				img_class = "img"
				div_class = ""
				if args.upstream_img:
					href = i
					title = "view remote image"
				elif 'video' in twat or 'ext_tw_video_thumb' in i:
					mp4_path = paths.get_user(twat['user']) + '/%s.mp4' % str(twat['id'])
					if os.path.exists(mp4_path):
						href = mp4_path
						title = "view local video"
					else:
						href = "https://twitter.com/i/status/" + twat['id']
						title = "view remote video"
					img_class = ""
					div_class = "video-thumbnail"
					span_or_div = "div"
				else:
					href = img_path
					title = "view local image"
				tw += '<a href="%s" title="%s"><%s class="%s"><img class="%s" src="%s" width="%d%%"></%s></a>' % (href, title, span_or_div, div_class, img_class, img_path, wdth, span_or_div)

		tw += '</p>\n'

	if 'quote' in twat:
		pseudo_twat = {
			'user' : twat['quote']['user'],
			'owner' : twat['quote']['user'],
			'id' : twat['quote']['id'],
			'text' : twat['quote']['text'],
			'time' : 0
		}
		tw += htmlize_twat(pseudo_twat, variables, quoted=True)

	tw += '</div>\n'

	return tw
예제 #6
0
def add_twatlist(user, twat, insert_pos):
	tweets[user].insert(insert_pos, twat)
	tweet_cache[user][get_effective_twat_id(twat)] = True
예제 #7
0
def in_twatlist(user, twat):
	eid = get_effective_twat_id(twat)
	return eid in tweet_cache[user]
예제 #8
0
def add_twatlist(user, twat, insert_pos):
    if not user in tweets: tweets[user] = list()
    if not user in tweet_cache: tweet_cache[user] = dict()
    tweets[user].insert(insert_pos, twat)
    tweet_cache[user][get_effective_twat_id(twat)] = True
예제 #9
0
def in_twatlist(user, twat):
    eid = get_effective_twat_id(twat)
    if user in tweet_cache and eid in tweet_cache[user]: return True
    else: return False