diff options
author | gabrielgio <gabriel.giovanini@pm.me> | 2021-07-14 21:23:44 +0200 |
---|---|---|
committer | gabrielgio <gabriel.giovanini@pm.me> | 2021-07-14 21:23:44 +0200 |
commit | 4d43e402b2b4e27bbbbfe557216d95963a27af72 (patch) | |
tree | 46f3013be10a1062280d64052bcb654d67084f91 /util.py | |
parent | 6887fcc0e42b1a64ed80f8565fe3099aaa818930 (diff) | |
download | reddit-nextcloud-importer-4d43e402b2b4e27bbbbfe557216d95963a27af72.tar.gz reddit-nextcloud-importer-4d43e402b2b4e27bbbbfe557216d95963a27af72.tar.bz2 reddit-nextcloud-importer-4d43e402b2b4e27bbbbfe557216d95963a27af72.zip |
feat: Add nextcloud path param
Add a new param to input the nextcloud root path.
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/util.py b/util.py deleted file mode 100644 index cd80506..0000000 --- a/util.py +++ /dev/null @@ -1,40 +0,0 @@ -import argparse -import json -import os -from time import sleep -from typing import Dict - -import jsonpickle -import requests - -headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - -parser = argparse.ArgumentParser(description="Monitor saved") -parser.add_argument('-c', '--client-id', help="Reddit client id", default=os.environ.get('CLIENT_ID', '')) -parser.add_argument('-s', '--client-secret', help="Reddit client secret", default=os.environ.get('CLIENT_SECRET', '')) -parser.add_argument('-u', '--reddit-username', help="Reddit username", default=os.environ.get('REDDIT_USERNAME', '')) -parser.add_argument('-p', '--reddit-password', help="Reddit user password", default=os.environ.get('REDDIT_PASSWORD', '')) -parser.add_argument('-P', '--nextcloud-password', help="Nextcloud Password", default=os.environ.get('NEXTCLOUD_PASSWORD', '')) -parser.add_argument('-U', '--nextcloud-username', help="Nextcloud Username", default=os.environ.get('NEXTCLOUD_USERNAME', '')) -parser.add_argument('-o', '--nextcloud-host', help="Nextcloud Host", default=os.environ.get('NEXTCLOUD_HOST', 'localhost')) - - -def try_post(url, json_string, count=0): - try: - if count > 10: - return - r = requests.post(url, data=json_string, headers=headers) - if r.status_code != 200: - sleep(60 * count) - try_post(url, json_string, count + 1) - except: - sleep(60 * count) - try_post(url, json_string, count + 1) - - -def jsonfy(post): - json_string = jsonpickle.encode(post) - json_dict: Dict = json.loads(json_string) - json_dict.pop('_reddit') - json_dict.pop('py/object') - return json.dumps(json_dict) |