Skip to content

Commit

Permalink
Clean-up warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
programmerPhysicist committed Aug 3, 2024
1 parent 5d656f4 commit 71c9436
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 141 deletions.
1 change: 1 addition & 0 deletions source/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import configparser


def getTodoistToken(configfile):
logging.debug('Loading todoist auth data from %s' % configfile)

Expand Down
17 changes: 9 additions & 8 deletions source/habitica.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@
from hab_task import HabTask

def get_all_habtasks(auth):
#Todoist tasks are, I think, classes. Let's make Habitica tasks classes, too.
# Todoist tasks are, I think, classes. Let's make Habitica tasks classes, too.
url = 'https://habitica.com/api/v3/tasks/user/'
# TODO: handle error cases for response
response = requests.get(url,headers=auth)
if response.ok == True:
response = requests.get(url, headers=auth)
if response.ok:
hab_raw = response.json()
"""FINALLY getting something I can work with... this will be a list of
dicts I want to turn into a list of objects with class hab_tasks.
Hrm. Weeeelll, if I make a class elsewhere...."""
# FINALLY getting something I can work with... this will be a list of
# dicts I want to turn into a list of objects with class hab_tasks.
# Hrm. Weeeelll, if I make a class elsewhere....
hab_tasklist = hab_raw['data']
else:
hab_tasklist = []
print(response.reason)

#keeping records of all our tasks
# keeping records of all our tasks
hab_tasks = []

#No habits right now, I'm afraid, in hab_tasks--Todoist gets upset. So we're going to make a list of dailies and todos instead...
# No habits right now, I'm afraid, in hab_tasks-Todoist gets upset. So we're going to make a list of dailies and
# todos instead...
for task in hab_tasklist:
item = HabTask(task)
if item.category == 'reward':
Expand Down
89 changes: 49 additions & 40 deletions source/main.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
#!/usr/bin/env python

"""
Main.py overdue for an overhaul! Let's see.
"""

"""Here's where we import stuff we need..."""
#import todoist
import requests
import json
from hab_task import HabTask
from todo_task import TodTask
# import json
# from datetime import datetime
# import todoist
# import re
import os
import logging
import configparser

from datetime import datetime
import sys
import requests
from dateutil import parser
import re


"""
Version control, basic paths
"""
from hab_task import HabTask
from todo_task import TodTask

# TODO: Main.py overdue for an overhaul! Let's see.
# Version control, basic paths
VERSION = 'Habitica-Plus-Todoist version 2.1.0'
TASK_VALUE_BASE = 0.9747 # http://habitica.wikia.com/wiki/Task_Value
HABITICA_REQUEST_WAIT_TIME = 0.5 # time to pause between concurrent requests
Expand Down Expand Up @@ -128,8 +120,9 @@ def check_matchDict(matchDict):
else:
print("something is weird check tod %s" % t)

def check_newMatches(matchDict,tod_uniq,hab_uniq):
#from main import add_hab_id

def check_newMatches(matchDict, tod_uniq, hab_uniq):
# from main import add_hab_id
matchesHab = []
matchesTod = []
for tod in tod_uniq:
Expand Down Expand Up @@ -174,6 +167,7 @@ def clean_matchDict(matchDict):
tod = matchDict[tid]['tod']
return matchDict


def complete_hab(hab):
import requests
import json
Expand All @@ -197,16 +191,18 @@ def delete_hab(hab):
return r

def get_all_habtasks(auth):
#Todoist tasks are, I think, classes. Let's make Habitica tasks classes, too.
# Todoist tasks are, I think, classes. Let's make Habitica tasks classes, too.
url = 'https://habitica.com/api/v3/tasks/user/'
response = requests.get(url,headers=auth)
response = requests.get(url, headers=auth)
hab_raw = response.json()
hab_tasklist = hab_raw['data'] #FINALLY getting something I can work with... this will be a list of dicts I want to turn into a list of objects with class hab_tasks. Hrm. Weeeelll, if I make a class elsewhere....
# FINALLY getting something I can work with... this will be a list of dicts I want to turn into a list of objects
# with class hab_tasks. Hrm. Weeeelll, if I make a class elsewhere....
hab_tasklist = hab_raw['data']

#keeping records of all our tasks
# keeping records of all our tasks
hab_tasks = []

#No habits right now, I'm afraid, in hab_tasks--Todoist gets upset. So we're going to make a list of dailies and todos instead...
# No habits right now, I'm afraid, in hab_tasks--Todoist gets upset. So we're going to make a list of dailies and todos instead...
for task in hab_tasklist:
item = HabTask(task)
if item.category == 'reward':
Expand All @@ -215,23 +211,25 @@ def get_all_habtasks(auth):
pass
else:
hab_tasks.append(item)
return(hab_tasks, response)
return (hab_tasks, response)


def get_hab_fromID(tid):
import requests
import json
auth = get_started('auth.cfg')
url = 'https://habitica.com/api/v3/tasks/'
url += str(tid)
r = requests.get(headers=auth, url=url)
if r.ok == True:
task = r.json()
response = requests.get(headers=auth, url=url)
if response.ok:
task = response.json()
hab = HabTask(task['data'])
else:
#TODO: log error
# TODO: log error
hab = HabTask()
return hab


def get_started(configfile):
"""Get Habitica authentication data from the AUTH_CONF file."""

Expand Down Expand Up @@ -267,8 +265,9 @@ def get_started(configfile):
# Return auth data as a dictionnary
return rv

def get_uniqs(matchDict,tod_tasks,hab_tasks):
# TODO: Rename this function

def get_uniqs(matchDict, tod_tasks, hab_tasks):
# TODO: Rename this function
tod_uniq = []
hab_uniq = []

Expand All @@ -285,7 +284,8 @@ def get_uniqs(matchDict,tod_tasks,hab_tasks):

return tod_uniq, hab_uniq

def getNewTodoTasks(matchDict,tod_tasks,hab_tasks):

def getNewTodoTasks(matchDict, tod_tasks, hab_tasks):
tod_uniq = []
hab_uniq = []

Expand Down Expand Up @@ -367,6 +367,8 @@ def make_daily_from_tod(tod):
finished_hab = HabTask(new_hab)
return finished_hab
'''


def make_hab_from_tod(tod_task):
new_hab = {'type':'todo'}
new_hab['text'] = tod_task.name
Expand Down Expand Up @@ -430,10 +432,11 @@ def make_tod_from_hab(hab):
rList.append(r,hab.name)
'''


def openMatchDict():
import pickle
try:
pkl_file = open('oneWay_matchDict.pkl','rb')
pkl_file = open('oneWay_matchDict.pkl', 'rb')
pkl_load = pickle.Unpickler(pkl_file)
matchDict = pkl_load.load()
pkl_file.close()
Expand Down Expand Up @@ -474,22 +477,24 @@ def purge_habs(hab_uniq, matchDict):

return hab_uniqest


def sync_hab2todo(hab, tod):
if hab.category == 'daily':
new_hab = sync_hab2todo_daily(hab,tod)
new_hab = sync_hab2todo_daily(hab, tod)
return new_hab
elif hab.category == 'todo':
new_hab = sync_hab2todo_todo(hab,tod)
new_hab = sync_hab2todo_todo(hab, tod)
return new_hab
else:
print("Error! Hab of incorrect type!")
exit(1)
sys.exit(1)


def sync_hab2todo_daily(hab, tod):
from dates import parse_date_utc
from datetime import datetime
# from datetime import datetime
from datetime import timedelta
import pytz
# import pytz
habDict = hab.task_dict
if tod.priority == 4:
habDict['priority'] = 2
Expand All @@ -498,7 +503,7 @@ def sync_hab2todo_daily(hab, tod):
else:
habDict['priority'] = 1

now = datetime.now().replace(tzinfo=pytz.utc).date()
# now = datetime.now().replace(tzinfo=pytz.utc).date()

if hab.due.date() != (tod.due.date() - timedelta(days=1)):
habDict['startDate'] = str(tod.due.date() - timedelta(days=1))
Expand Down Expand Up @@ -599,6 +604,7 @@ def syncHistories(matchDict):
return matchDict
'''


def update_hab(hab):
# TODO: Only update when there are actual changes
import requests
Expand All @@ -619,6 +625,7 @@ def update_hab(hab):
print(r.text)
return r


def update_hab_matchDict(hab_tasks, matchDict):
from main import delete_hab
from main import sync_hab2todo
Expand Down Expand Up @@ -685,6 +692,7 @@ def update_hab_matchDict(hab_tasks, matchDict):

return matchDict


def update_tod_matchDict(tod_tasks, matchDict):
tid_list = []
for tod in tod_tasks:
Expand All @@ -697,6 +705,7 @@ def update_tod_matchDict(tod_tasks, matchDict):

return matchDict


def write_hab_task(task):
"""
writes a task, if inserted, to Habitica API as a todo.
Expand Down
Loading

0 comments on commit 71c9436

Please sign in to comment.