Commit 3fce83dc authored by Cody Zacharias's avatar Cody Zacharias Committed by GitHub

Update following.py

parent 06bf75da
from . import feed, get, db, output, elasticsearch from . import feed, get, db, output, elasticsearch
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import aiohttp
import asyncio import asyncio
import re import re
import sys import sys
...@@ -12,8 +11,11 @@ class Following: ...@@ -12,8 +11,11 @@ class Following:
self.count = 0 self.count = 0
self.config = config self.config = config
if 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)
...@@ -23,22 +25,21 @@ class Following: ...@@ -23,22 +25,21 @@ class Following:
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).following()
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).following())
self.feed = [] self.feed = []
try: try:
self.feed, self.init = feed.Follow(response) self.feed, self.init = feed.Follow(response)
except Exception as e: except Exception as e:
pass pass
return self.feed return self.feed
async def following(self): async def following(self):
await self.Feed() await self.Feed()
for f in self.feed: for f in self.feed:
User = await output.getUser(f) User = await output.getUser(f)
if self.config.Database: if self.config.Database:
db.following(self.conn, self.config.Username, User.name) db.following(self.conn, self.config.Username, User.name)
...@@ -46,14 +47,16 @@ class Following: ...@@ -46,14 +47,16 @@ class Following:
output.write(User.name, self.config.Output) output.write(User.name, self.config.Output)
if self.config.Elasticsearch: if self.config.Elasticsearch:
elasticsearch.Follow(self.config.Elasticsearch, self.config.Username, User.name, self.config.Essid) elasticsearch.Follow(self.config.Elasticsearch, self.config.Username,
User.name, self.config.Essid)
self.count += 1 self.count += 1
print(User.name) print(User.name)
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.following() await self.following()
......
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