-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an ini file to configure certain settings
- Loading branch information
Showing
13 changed files
with
64 additions
and
24 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
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
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
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 |
---|---|---|
|
@@ -9,17 +9,17 @@ | |
from requests import codes | ||
|
||
from ao3downloader import exceptions, parse_soup, parse_text, strings | ||
from ao3downloader.fileio import FileOps | ||
|
||
|
||
class Repository: | ||
|
||
# for reasons I don't fully understand, specifying the user agent makes requests faster | ||
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit' | ||
'/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36 [email protected]'} | ||
headers = {'user-agent': 'ao3downloader [email protected]'} | ||
|
||
|
||
def __init__(self) -> None: | ||
def __init__(self, fileops: FileOps) -> None: | ||
self.session = requests.Session() | ||
self.extra_wait = int(fileops.get_ini_value(strings.INI_WAIT_TIME, '0')) | ||
|
||
|
||
def __enter__(self): | ||
|
@@ -63,13 +63,16 @@ def my_get(self, url: str) -> requests.Response: | |
pause_time = int(response.headers['retry-after']) | ||
except: | ||
pause_time = 300 # default to 5 minutes in case there was a problem getting retry-after | ||
if pause_time < 0: pause_time = 300 # also do 5 minutes if retry-after was found but is invalid | ||
now = datetime.datetime.now() | ||
later = now + datetime.timedelta(0, pause_time) | ||
print(strings.MESSAGE_TOO_MANY_REQUESTS.format(pause_time, now.strftime('%H:%M:%S'), later.strftime('%H:%M:%S'))) | ||
sleep(pause_time) | ||
print(strings.MESSAGE_RESUMING) | ||
return self.my_get(url) | ||
|
||
if self.extra_wait > 0: sleep(self.extra_wait) | ||
|
||
return response | ||
|
||
|
||
|
@@ -79,7 +82,7 @@ def login(self, username: str, password: str): | |
soup = self.get_soup(strings.AO3_LOGIN_URL) | ||
token = parse_soup.get_token(soup) | ||
payload = parse_text.get_payload(username, password, token) | ||
response = self.session.post(strings.AO3_LOGIN_URL, data=payload) | ||
response = self.session.post(strings.AO3_LOGIN_URL, data=payload, headers=self.headers) | ||
soup = BeautifulSoup(response.text, 'html.parser') | ||
if parse_soup.is_failed_login(soup): | ||
raise exceptions.LoginException(strings.ERROR_FAILED_LOGIN) |
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,14 @@ | ||
[settings] | ||
|
||
# this is the number of seconds to wait between each hit to ao3 IN | ||
# ADDITION to the required wait times when the rate limit is hit. | ||
# you may wish to set this above zero if you feel that you are | ||
# hitting the rate limit too often, or if you wish to avoid hitting | ||
# the rate limit for some reason (like if you are actively browsing | ||
# while the script is running, or you encounter rate-limit related bugs) | ||
ExtraWaitTime=0 | ||
|
||
# if you set this to 'false' your password will not be saved in settings. | ||
# note that if you already saved your password on a previous run, it will | ||
# not be deleted. to fix this you can delete the 'settings.json' file | ||
SavePassword=true |