Commit 6aa4d5e9 authored by Cody Zacharias's avatar Cody Zacharias Committed by GitHub

Update favorites.py

parent b3b4a776
from . import feed, get, db, output from . import feed, get, db, output
import aiohttp
import asyncio import asyncio
import concurrent.futures import concurrent.futures
import re import re
import sys import sys
class Favorites: class Favorites:
def __init__(self, config): def __init__(self, config):
self.init = -1 self.init = -1
self.feed = [-1] self.feed = [-1]
self.count = 0 self.count = 0
self.config = config self.config = config
if self.config.Elasticsearch: if self.config.Elasticsearch:
print("Indexing to Elasticsearch @ " + str(self.config.Elasticsearch)) print("[+] Indexing to Elasticsearch @ " + str(self.config.Elasticsearch))
if self.config.Database: if self.config.Database:
print("Inserting into Database: " + str(self.config.Database)) print("[+] Inserting into Database: " + str(self.config.Database))
self.conn = db.init(self.config.Database) self.conn = db.init(self.config.Database)
if isinstance(self.conn, str): if isinstance(self.conn, str):
print(str) print(str)
sys.exit(1) sys.exit(1)
else: else:
self.conn = "" self.conn = ""
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete(self.main()) loop.run_until_complete(self.main())
async def Feed(self): async def Feed(self):
ua = {'User-Agent': 'Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/0.8.12'} url = await get.Url(self.config, self.init).favorites()
connect = aiohttp.TCPConnector(verify_ssl=False) response = await get.MobileRequest(self.config, url)
async with aiohttp.ClientSession(headers=ua, connector=connect) as session: self.feed = []
response = await get.Response(session, await get.Url(self.config, try:
self.init).favorites()) self.feed, self.init = feed.Favorite(response)
self.feed = [] except:
try: pass
self.feed, self.init = feed.Favorite(response)
except:
pass
return self.feed
async def favorites(self): return self.feed
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:
pass
async def main(self): async def favorites(self):
if self.config.User_id is not None: await self.Feed()
self.config.Username = await get.Username(self.config.User_id) try:
while True: with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
if len(self.feed) > 0: loop = asyncio.get_event_loop()
await self.favorites() futures = []
else: for tweet in self.feed:
break 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)))
if self.config.Limit is not None and self.count >= int(self.config.Limit): await asyncio.gather(*futures)
break except:
pass
if self.config.Count: async def main(self):
print("[+] Finished: Successfully collected {0.count} Tweets that @{0.config.Username} liked.".format(self)) if self.config.User_id is not None:
self.config.Username = await get.Username(self.config)
while True:
if len(self.feed) > 0:
await self.favorites()
else:
break
if self.config.Limit is not None and self.count >= int(self.config.Limit):
break
if self.config.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