Commit ad845e15 authored by Raphael Beer's avatar Raphael Beer

Add: count sensitive flags on user's latest tweets

parent 9d137208
......@@ -12,8 +12,9 @@ import time
from aiohttp import web
from bs4 import BeautifulSoup
from db import connect
from db import connect
from statistics import count_sensitives
from typeahead import test as test_typeahead
routes = web.RouteTableDef()
......@@ -421,6 +422,8 @@ class TwitterSession:
if not profile["exists"] or profile.get("suspended", False) or profile.get("protected", False) or not profile.get('has_tweets'):
return result
result["profile"]["sensitives"] = await count_sensitives(self, user_id)
result["tests"] = {}
search_raw = await self.search_raw("from:@" + username)
......
import sys
# Count amount of "possibly_sensitive_editable" and "possibly_sensitive"
# flagged tweets in user's timeline
async def count_sensitives(session, user_id):
profile_timeline = await session.get_profile_tweets_raw(user_id)
profile_tweets = profile_timeline["globalObjects"]["tweets"].values()
counted = len(profile_tweets)
possibly_sensitive = len([1 for tweet in profile_tweets if "possibly_sensitive" in tweet.keys()])
possibly_sensitive_editable = len([1 for tweet in profile_tweets if "possibly_sensitive_editable" in tweet.keys()])
result = {
"counted": counted,
"possibly_sensitive": possibly_sensitive,
"possibly_sensitive_editable": possibly_sensitive_editable
}
return result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment