Commit 16935352 authored by andytnt's avatar andytnt

Modify output.py

parent e380cdb2
...@@ -31,7 +31,7 @@ def datecheck(datestamp, config): ...@@ -31,7 +31,7 @@ def datecheck(datestamp, config):
def is_tweet(tw): def is_tweet(tw):
#logging.info("[<] " + str(datetime.now()) + ':: output+is_tweet') #logging.info("[<] " + str(datetime.now()) + ':: output+is_tweet')
try: try:
tw.find("div")["data-item-id"] tw["data-item-id"]
return True return True
except: except:
return False return False
...@@ -79,9 +79,15 @@ def _output(obj, output, config, **extra): ...@@ -79,9 +79,15 @@ def _output(obj, output, config, **extra):
except UnicodeEncodeError: except UnicodeEncodeError:
print("unicode error [x] output._output") print("unicode error [x] output._output")
async def tweetUserData(tweet,config, conn): async def checkData(tweet, location, config, conn):
user_ids = set()
usernames = [] usernames = []
user_ids = set()
global _duplicate_dict
copyright = tweet.find("div", "StreamItemContent--withheld")
if copyright is None and is_tweet(tweet):
tweet = Tweet(tweet, location, config)
if config.Database is not None and config.User_info:
for user in tweet.mentions: for user in tweet.mentions:
if db.get_user_id(conn, user["id"]) == -1 and user["id"] not in user_ids: if db.get_user_id(conn, user["id"]) == -1 and user["id"] not in user_ids:
user_ids.add(user["id"]) user_ids.add(user["id"])
...@@ -94,20 +100,12 @@ async def tweetUserData(tweet,config, conn): ...@@ -94,20 +100,12 @@ async def tweetUserData(tweet,config, conn):
if db.get_user_id(conn, user["id"]) == -1 and user["id"] not in user_ids: if db.get_user_id(conn, user["id"]) == -1 and user["id"] not in user_ids:
user_ids.add(user["id"]) user_ids.add(user["id"])
usernames.append(user["screen_name"]) usernames.append(user["screen_name"])
if config.Database is not None and config.User_info:
for user in usernames: for user in usernames:
url = f"http://twitter.com/{user}?lang=en" url = f"http://twitter.com/{user}?lang=en"
await get.User(url, config, conn) await get.User(url, config, conn)
async def Tweets(tw, location, config, conn):
#logging.info("[<] " + str(datetime.now()) + ':: output+Tweets')
global _duplicate_dict
copyright = tw.find("div", "StreamItemContent--withheld")
if copyright is None and is_tweet(tw):
tweet = Tweet(tw, location, config)
if config.Database is not None and config.User_info:
await tweetUserData(tweet, config, conn)
if config.User_info: if config.User_info:
for user in tweet.mentions: for user in tweet.mentions:
try: try:
...@@ -151,6 +149,20 @@ async def Tweets(tw, location, config, conn): ...@@ -151,6 +149,20 @@ async def Tweets(tw, location, config, conn):
_output(tweet, output, config) _output(tweet, output, config)
async def Tweets(tweets, location, config, conn, url=''):
if (config.Profile_full or config.Location) and config.Get_replies:
for tw in tweets:
await checkData(tw, location, config, conn)
elif config.Favorites or config.Profile_full or config.Location:
for tw in tweets:
if tw['data-item-id'] == url.split('?')[0].split('/')[-1]:
await checkData(tw, location, config, conn)
elif config.TwitterSearch:
await checkData(tweets, location, config, conn)
else:
if int(tweets["data-user-id"]) == config.User_id:
await checkData(tweets, location, config, conn)
async def Users(u, config, conn): async def Users(u, config, conn):
#logging.info("[<] " + str(datetime.now()) + ':: output+Users') #logging.info("[<] " + str(datetime.now()) + ':: output+Users')
global user_object global user_object
......
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