-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganization & Starting to make profiles a bit less overcomplicated
utils.py * Moved file into InstaTweet directory and deleted utils directory because why did that even exist * Changed UserAgent class to get_agent() function because again, for what? Having it as a class that uses hardcoded user agents didn't make sense, now it'll scrape the standard chrome agent from whatismybrowser.com * Updated get_root to be correct ----- instatweet.py I overcomplicated things when I first wrote this in November (?). Now that I know better I'm trying to simplify it, but it's hard without breaking everything!! Those memes were not lying oh my god. Anyways, the goal is to make it really simple to use the local/hosted version of InstaTweet. Hosted DB version works great but I can't push that until this is all sorted out... so... * Fixed bug where specifying a profile name as a kwarg when initializing InstaTweet would break everything 😍 -If you specify a name it will now attempt to load the profile immediately (instead of setting all attributes first, trying to save a half-initialized profile, and raising an exception) * Added profile name to config property and by extension, the saved profile .txt files (this is actually what broke it)
- Loading branch information
Showing
6 changed files
with
43 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
import requests | ||
from pathlib import Path | ||
from bs4 import BeautifulSoup as bs | ||
|
||
BACKUP_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36' | ||
|
||
|
||
def get_agent(): | ||
r = requests.get('https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome') | ||
if r.ok: | ||
soup = bs(r.text, 'html.parser') | ||
if soup_agents := soup.find_all('span', {'class': 'code'}): | ||
return soup_agents[0].text | ||
# If function fails to scrape, will use hardcoded user agent | ||
return BACKUP_AGENT | ||
|
||
|
||
def get_root(): | ||
return Path(__file__).parent | ||
|
||
|
||
def get_filepath(filename, filetype='.txt'): | ||
return os.path.join(get_root(), filename) + filetype |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.