Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Added initial support for logging in.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulfre committed Mar 24, 2020
1 parent 1ae15b0 commit a169e6a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
23 changes: 16 additions & 7 deletions e621dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
if __name__ == '__main__':
# Create the requests session that will be used throughout the run.
with remote.requests_retry_session() as session:
# Set the user-agent. Requirements are specified at https://e621.net/help/show/api#basics.
# Set the user-agent. Requirements are specified at https://e621.net/wiki_pages/2425#Basics.
session.headers['User-Agent'] = f"e621dl.py/{constants.VERSION} (by Wulfre)"

# Check if a new version is released on github. If so, notify the user.
if StrictVersion(constants.VERSION) < StrictVersion(remote.get_github_release(session)):
print('A NEW VERSION OF e621dl IS AVAILABLE ON GITHUB AT https://github.com/Wulfre/e621dl/releases/latest.')

print(f"[i] Running e621dl version {constants.VERSION}.")
print('')
print("[i] Checking for partial downloads...")

remote.finish_partial_downloads(session)

print('')
print("[i] Parsing config...")
Expand All @@ -36,9 +32,18 @@
# Initialize the lists that will be used to filter posts.
searches = []

# Initialize last_id
# Initialize last_id.
last_id = None

# Initialize login information.
login = {
'username': config['login'].get('username'),
'api_key': config['login'].get('api_key')
}

if login['username'] or login['api_key'] == None:
print('[i] No login detected. Some posts may be hidden and unable to be downloaded.')

# Initialize user configured options in case any are missing.
default_days = config['default_search'].get('days', 1)
default_score = config['default_search'].get('min_score', -0x7F_FF_FF_FF)
Expand Down Expand Up @@ -70,6 +75,10 @@
'earliest_date': section_date
})

print('')
print("[i] Checking for partial downloads...")
remote.finish_partial_downloads(session)

for search in searches:
print('')

Expand All @@ -83,7 +92,7 @@
# Sets up a loop that will continue indefinitely until the last post of a search has been found.
while True:
print("[i] Getting posts...")
results = remote.get_posts(search_string, search['earliest_date'], last_id, session)['posts']
results = remote.get_posts(search_string, search['earliest_date'], last_id, login, session)['posts']

# Gets the id of the last post found in the search so that the search can continue.
try:
Expand Down
6 changes: 5 additions & 1 deletion e621dl/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
MAX_TAGS = 38
PARTIAL_DOWNLOAD_EXT = 'request'

DEFAULT_CONFIG_TEXT = '''default_search:
DEFAULT_CONFIG_TEXT = '''login:
username:
api_key:
default_search:
days: 1
min_score: 0
min_favs: 0
Expand Down
6 changes: 4 additions & 2 deletions e621dl/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ def get_github_release(session):

return response.json()['tag_name'].strip('v')

def get_posts(search_string, earliest_date, last_id, session):
def get_posts(search_string, earliest_date, last_id, login, session):
url = 'https://e621.net/posts.json'
payload = {
'limit': constants.MAX_RESULTS,
'tags': f"date:>={earliest_date} {search_string}"
'tags': f"date:>={earliest_date} {search_string}",
'login': login['username'],
'api_key': login['api_key']
}

if last_id:
Expand Down

0 comments on commit a169e6a

Please sign in to comment.