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

Update get.py

parent 3fce83dc
...@@ -10,30 +10,40 @@ class Url: ...@@ -10,30 +10,40 @@ class Url:
self.init = init self.init = init
async def favorites(self): async def favorites(self):
if self.init == -1:
url = "https://mobile.twitter.com/{0.Username}/favorites?lang=en".format(self.config) url = "https://mobile.twitter.com/{0.Username}/favorites?lang=en".format(self.config)
else:
url = "https://mobile.twitter.com/{0.Username}/favorites?max_id={1.init}&lang=en".format(self.config, self) if self.init != -1:
url+= "&max_id={0.init}".format(self)
return url return url
async def followers(self): async def followers(self):
if self.init == -1:
url = "https://mobile.twitter.com/{0.Username}/followers?lang=en".format(self.config) url = "https://mobile.twitter.com/{0.Username}/followers?lang=en".format(self.config)
else:
url = "https://mobile.twitter.com/{0.Username}/followers?cursor={1.init}&lang=en".format(self.config, self) if self.init != -1:
url+= "&cursor={0.init}".format(self)
return url return url
async def following(self): async def following(self):
if self.init == -1:
url = "https://mobile.twitter.com/{0.Username}/following?lang=en".format(self.config) url = "https://mobile.twitter.com/{0.Username}/following?lang=en".format(self.config)
else:
url = "https://mobile.twitter.com/{0.Username}/following?cursor={1.init}&lang=en".format(self.config, self) if self.init != -1:
url+= "&cursor={0.init}".format(self)
return url
async def profile(self):
url = "https://twitter.com/i/profiles/show/{0.Username}/timeline/tweets".format(self.config)
url+= "?include_available_features=1&lang=en&include_entities=1&include"
url+= "_new_items_bar=true"
if self.init != -1:
url+= "&max_position={0.init}".format(self)
return url return url
async def search(self): async def search(self):
if self.init == -1:
url = "https://twitter.com/search?f=tweets&vertical=default&lang=en&q="
else:
url = "https://twitter.com/i/search/timeline?f=tweets&vertical=default" url = "https://twitter.com/i/search/timeline?f=tweets&vertical=default"
url+= "&lang=en&include_available_features=1&include_entities=1&reset_" url+= "&lang=en&include_available_features=1&include_entities=1&reset_"
url+= "error_state=false&src=typd&max_position={0.init}&q=".format(self) url+= "error_state=false&src=typd&max_position={0.init}&q=".format(self)
...@@ -61,7 +71,7 @@ class Url: ...@@ -61,7 +71,7 @@ class Url:
url+= "%20OR%20phone%20OR%20call%20me%20OR%20text%20me" url+= "%20OR%20phone%20OR%20call%20me%20OR%20text%20me"
url+= "%20OR%20keybase" url+= "%20OR%20keybase"
if self.config.Verified: if self.config.Verified:
url+= "%20filter%3Averfied" url+= "%20filter%3Averified"
if self.config.To: if self.config.To:
url+= "%20to%3A{0.To}".format(self.config) url+= "%20to%3A{0.To}".format(self.config)
if self.config.All: if self.config.All:
...@@ -70,29 +80,41 @@ class Url: ...@@ -70,29 +80,41 @@ class Url:
self.config.Near = self.config.Near.replace(" ", "%20") self.config.Near = self.config.Near.replace(" ", "%20")
self.config.Near = self.config.Near.replace(",", "%2C") self.config.Near = self.config.Near.replace(",", "%2C")
url+= "%20near%3A{0.Near}".format(self.config) url+= "%20near%3A{0.Near}".format(self.config)
return url return url
async def MobileRequest(config, url):
ua = {'User-Agent': 'Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/0.8.12'}
connect = aiohttp.TCPConnector(verify_ssl=False)
async with aiohttp.ClientSession(headers=ua, connector=connect) as session:
return await Response(session, url)
async def Request(config, url):
connect = aiohttp.TCPConnector(verify_ssl=False)
async with aiohttp.ClientSession(connector=connect) as session:
return await Response(session, url)
async def Response(session, url): async def Response(session, url):
with async_timeout.timeout(30): with async_timeout.timeout(30):
async with session.get(url) as response: async with session.get(url) as response:
return await response.text() return await response.text()
async def Username(userid): async def Username(config):
connect = aiohttp.TCPConnector(verify_ssl=False) url = "https://twitter.com/intent/user?user_id={}&lang=en".format(config.User_id)
async with aiohttp.ClientSession(connector=connect) as session: r = Request(config, url)
r = await Response(session, "https://twitter.com/intent/user?user_id={}&lang=en".format(userid))
soup = BeautifulSoup(r, "html.parser") soup = BeautifulSoup(r, "html.parser")
return soup.find("a", "fn url alternate-context")["href"].replace("/", "") return soup.find("a", "fn url alternate-context")["href"].replace("/", "")
async def Tweet(url, config, conn): async def Tweet(url, config, conn):
try: try:
connect = aiohttp.TCPConnector(verify_ssl=False) response = await Request(config, url)
async with aiohttp.ClientSession(connector=connect) as session:
response = await Response(session, url)
soup = BeautifulSoup(response, "html.parser") soup = BeautifulSoup(response, "html.parser")
tweet = soup.find("div", "permalink-inner permalink-tweet-container") tweet = soup.find("div", "permalink-inner permalink-tweet-container")
# Experimental location = soup.find("span", "ProfileHeaderCard-locationText u-dir").text
location = soup.find("span", "ProfileHeaderCard-locationText u-dir").text.replace("\n", "").replace(" ", "").replace(",", ", ") location = location.replace("\n", "")
location = location.replace(" ", "")
location = location.replace(",", ", ")
await output.Tweets(tweet, location, config, conn) await output.Tweets(tweet, location, config, conn)
except: except:
pass pass
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