initial commit
This commit is contained in:
40
ghostfolio_service.py
Normal file
40
ghostfolio_service.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import logging
|
||||
|
||||
import requests
|
||||
import simplejson as json
|
||||
import ntfy_service
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_bearer_token():
|
||||
response = requests.post('http://192.168.1.202:3333/api/v1/auth/anonymous', data={
|
||||
"accessToken": "cab07a6b0a87711013ee5457411a26c7c7dd2787830b64b914d5678d4dc54af911752975380467fd73c3798b043855520ab148a372d8fd859860703833e96cba"}
|
||||
)
|
||||
|
||||
token = response.json()['authToken']
|
||||
|
||||
return token
|
||||
|
||||
|
||||
def import_activities(activities_json, filename: str):
|
||||
bearer_token = get_bearer_token()
|
||||
|
||||
data = json.dumps(activities_json)
|
||||
|
||||
response = requests.post('http://192.168.1.202:3333/api/v1/import', data=data,
|
||||
headers={"Authorization": "Bearer " + bearer_token, "Content-Type": "application/json"})
|
||||
|
||||
print(response.json())
|
||||
|
||||
if len(response.json()['activities']) < 1:
|
||||
logger.info(f'No activity imported for {filename}')
|
||||
print(f'No activity imported for {filename}')
|
||||
ntfy_service.send_notification(f'No activity imported for {filename}')
|
||||
else:
|
||||
ntfy_service.send_notification(f'Imported {len(response.json()['activities'])} activities from {filename}')
|
||||
print(f'Imported {len(response.json()['activities'])} activities from {filename}')
|
||||
|
||||
# print(json.dumps(response.json(), indent=4))
|
||||
|
||||
return response.status_code
|
||||
Reference in New Issue
Block a user