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
...@@ -13,10 +12,10 @@ class Favorites: ...@@ -13,10 +12,10 @@ class Favorites:
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)
...@@ -28,16 +27,14 @@ class Favorites: ...@@ -28,16 +27,14 @@ class Favorites:
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:
response = await get.Response(session, await get.Url(self.config,
self.init).favorites())
self.feed = [] self.feed = []
try: try:
self.feed, self.init = feed.Favorite(response) self.feed, self.init = feed.Favorite(response)
except: except:
pass pass
return self.feed return self.feed
async def favorites(self): async def favorites(self):
...@@ -50,7 +47,8 @@ class Favorites: ...@@ -50,7 +47,8 @@ class Favorites:
self.count += 1 self.count += 1
link = tweet.find("a")["href"] link = tweet.find("a")["href"]
url = "https://twitter.com{}&lang=en".format(link) url = "https://twitter.com{}&lang=en".format(link)
futures.append(loop.run_in_executor(executor, await get.Tweet(url, self.config, self.conn))) futures.append(loop.run_in_executor(executor, await get.Tweet(url,
self.config, self.conn)))
await asyncio.gather(*futures) await asyncio.gather(*futures)
except: except:
...@@ -58,7 +56,8 @@ class Favorites: ...@@ -58,7 +56,8 @@ class Favorites:
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.User_id) self.config.Username = await get.Username(self.config)
while True: while True:
if len(self.feed) > 0: if len(self.feed) > 0:
await self.favorites() await self.favorites()
......
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