-
-
Notifications
You must be signed in to change notification settings - Fork 3
Populate more #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d426a9a
2028a07
35d33ad
7a6bb4f
548a7c8
72eb198
f73ea37
a406f34
a9ef43c
2e9adaa
ac7cad8
e201de1
c7013e0
31f4c0f
9cc3eba
c4a2424
87ad960
7a72148
d0b12e0
9fa4f67
0ec2219
b6f0d70
5e739b6
6733f12
5b526c1
bf88240
ab00a16
235ac6b
31b180e
25bf9b6
826c4d1
242f34f
2876a95
166e7c4
14ca30f
c6e1efd
5cc2a27
9a12e44
134dcc2
7400db2
e782ff1
f5dd8e2
d2f7db1
26c4920
62c286a
3f3408b
aa11afa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #! /usr/bin/python3 | ||
|
|
||
| from requests import get | ||
| import sys | ||
| headers = {'host': 'meta.miraheze.org'} | ||
| response = get('https://localhost/w/api.php?action=query&meta=siteinfo&formatversion=2&format=json', headers=headers, verify=False).json() | ||
| if not response['query']['general']['readonly']: | ||
| print('Site is READ-WRITE') | ||
| sys.exit(0) | ||
| else: | ||
| print(response['query']['general']['readonlyreason']) | ||
| sys.exit(1) | ||
|
Comment on lines
+6
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential exceptions from network requests. The script does not handle exceptions that may occur during the HTTP request (e.g., network errors, invalid responses). Consider adding error handling to manage these scenarios gracefully. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #! /usr/bin/python3 | ||
|
|
||
| # Upload files to archive.org directly | ||
| # from the command line. | ||
| # | ||
| # Universal Omega 2022 | ||
|
|
||
| import argparse | ||
| import internetarchive | ||
| import os | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| class ArchiveUploader: | ||
| def __init__(self) -> None: | ||
| self.parser = argparse.ArgumentParser( | ||
| description='Uploads a file to archive.org.') | ||
| self.parser.add_argument( | ||
| '--title', dest='title', required=True, | ||
| help='The title of the file to be used on archive.org. Will be both the title and identifier. Required.') | ||
| self.parser.add_argument( | ||
| '--description', dest='description', default='', | ||
| help='The description of the file to be used on archive.org. Optional. Default: empty') | ||
| self.parser.add_argument( | ||
| '--mediatype', dest='mediatype', default='web', | ||
| help='The media type of the file to be used on archive.org. Optional. Default: web') | ||
| self.parser.add_argument( | ||
| '--subject', dest='subject', default='wikitide;wikiteam', | ||
| help='Subject (topics) of the file for archive.org. Multiple topics can be separated by a semicolon. Optional. Default: wikitide;wikiteam') | ||
| self.parser.add_argument( | ||
| '--collection', dest='collection', default='opensource', | ||
| help='The name of the collection to use on archive.org. Optional. Default: opensource') | ||
| self.parser.add_argument( | ||
| '--file', dest='file', required=True, | ||
| help='The local path to the file to be uploaded to archive.org. Required.') | ||
| self.parser.add_argument( | ||
| '--proxy', dest='proxy', default='http://bastion.wikitide.net:8080', | ||
| help='The proxy to use for requests to archive.org. Optional. Default: http://bastion.wikitide.net:8080') | ||
|
|
||
| def upload(self) -> None: | ||
| args = self.parser.parse_args() | ||
|
|
||
| item = internetarchive.get_item(args.title) | ||
|
|
||
| if args.proxy: | ||
| # set HTTP proxy to use for getting the item from archive.org | ||
| # we then also set the session proxy for the item to use for uploading | ||
| # but we can't get the item to set session proxy without also setting HTTP_PROXY here | ||
| os.environ['HTTP_PROXY'] = args.proxy | ||
| os.environ['HTTPS_PROXY'] = args.proxy | ||
|
|
||
| # set session proxy for uploading | ||
| item.session.proxies = { | ||
| 'http': args.proxy, | ||
| 'https': args.proxy, | ||
| } | ||
|
|
||
| # get last modification time from file to use as the publication date in archive.org | ||
| mtime = os.path.getmtime(args.file) | ||
| dt = datetime.fromtimestamp(mtime) | ||
| date = datetime.strftime(dt, '%Y-%m-%d') | ||
|
|
||
| # set metadata | ||
| # see https://archive.org/developers/metadata-schema for valid options | ||
| md = { | ||
| 'collection': args.collection, | ||
| 'date': date, | ||
| 'description': args.description, | ||
| 'mediatype': args.mediatype, | ||
| 'subject': args.subject, | ||
| 'title': args.title, | ||
| } | ||
|
|
||
| # actually upload the file | ||
| item.upload(args.file, metadata=md, verbose=True, queue_derive=False) | ||
|
Comment on lines
+41
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate user input before processing. The script processes command line arguments directly without validating them, which could lead to security issues or errors. Consider adding validation for the command line arguments to ensure they meet expected formats and constraints. |
||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| uploader = ArchiveUploader() | ||
| uploader.upload() | ||
Uh oh!
There was an error while loading. Please reload this page.