Commit f12707de authored by Cody Zacharias's avatar Cody Zacharias Committed by GitHub

1.1.3 Update

parent fbaf1c8c
from . import feed, get, db, output from . import feed, get, db, output, verbose
import asyncio
import concurrent.futures
import re
import sys
class Favorites: class Favorites:
def __init__(self, config): def __init__(self, config):
...@@ -10,62 +6,30 @@ class Favorites: ...@@ -10,62 +6,30 @@ class Favorites:
self.feed = [-1] self.feed = [-1]
self.count = 0 self.count = 0
self.config = config self.config = config
self.conn = db.Conn(config.Database)
if self.config.Elasticsearch: self.config.Favorites = True
print("[+] Indexing to Elasticsearch @ " + str(self.config.Elasticsearch))
verbose.Elastic(config)
if self.config.Database:
print("[+] Inserting into Database: " + str(self.config.Database))
self.conn = db.init(self.config.Database)
if isinstance(self.conn, str):
print(str)
sys.exit(1)
else:
self.conn = ""
loop = asyncio.get_event_loop()
loop.run_until_complete(self.main())
async def Feed(self): async def Feed(self):
url = await get.Url(self.config, self.init).favorites() response = await get.RequestUrl(self.config, self.init)
response = await get.MobileRequest(self.config, url)
self.feed = [] self.feed = []
try: try:
self.feed, self.init = feed.Favorite(response) self.feed, self.init = feed.Mobile(response)
except:
pass
return self.feed
async def favorites(self):
await self.Feed()
try:
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
loop = asyncio.get_event_loop()
futures = []
for tweet in self.feed:
self.count += 1
link = tweet.find("a")["href"]
url = "https://twitter.com{}&lang=en".format(link)
futures.append(loop.run_in_executor(executor, await get.Tweet(url,
self.config, self.conn)))
await asyncio.gather(*futures)
except: except:
pass pass
async def main(self): async def main(self):
if self.config.User_id is not None: if self.config.User_id is not None:
self.config.Username = await get.Username(self.config) self.config.Username = await get.Username(self.config.User_id)
while True: while True:
if len(self.feed) > 0: if len(self.feed) > 0:
await self.favorites() await self.Feed()
else: self.count += await get.Multi(self.feed, self.config, self.conn)
elif get.Limit(self.config.Limit, self.count):
break break
else:
if self.config.Limit is not None and self.count >= int(self.config.Limit):
break break
if self.config.Count: verbose.Count(self.config, self.count)
print("[+] Finished: Successfully collected {0.count} Tweets that @{0.config.Username} liked.".format(self))
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