def test_offline(self): out = StringIO.StringIO() online.main(out, lambda x: False, ["one", "two"]) self.assertEqual(out.getvalue(), """\ verbose "one offline" verbose "two offline" set variable "ONLINE_STATUS" "OFFLINE" verbose "Hosts offline" """) out.close()
def main(): with open('todoist_API.txt') as f: # Opens the API key file token = f.readline() # Sets the first line of the txt file as your API Key if online.main() == False: with open("todoist.cache", "rb") as myFile: loaded_cache = pickle.load(myFile) rank = 0 for i in loaded_cache: #going through all the items in todoist if i['project_id'] == 170911352: # if an item is in the inbox if i['checked'] == 0: # if the item is incomplete if i['priority'] == 1: pri = "<p class='priority4'>" elif i['priority'] == 2: pri = "<p class='priority3'>" elif i['priority'] == 3: pri = "<p class='priority2'>" elif i['priority'] == 4: pri = "<p class='priority1'>" rank += 1 print(pri, "<b>", rank, '- </b>', i['content'], "</p>") # print name and id elif online.main() == True: from todoist.api import TodoistAPI api = TodoistAPI(token) api.sync() # initial sync if os.path.exists("todoist.cache"): # Delete old cache os.remove("todoist.cache") open("todoist.cache", 'a').close() # Initialise new cache # https://stackoverflow.com/questions/17322273/store-a-dictionary-in-a-file-for-later-retrieval with open("todoist.cache", "wb") as myFile: pickle.dump(api.state['items'], myFile) rank = 0 for i in api.state['items']: #going through all the items in todoist if i['project_id'] == 170911352: # if an item is in the inbox if i['checked'] == 0: # if the item is incomplete if i['priority'] == 1: pri = "<p class='priority4'>" elif i['priority'] == 2: pri = "<p class='priority3'>" elif i['priority'] == 3: pri = "<p class='priority2'>" elif i['priority'] == 4: pri = "<p class='priority1'>" # FIXME: Color coding not working... rank += 1 print(pri, "<b>", rank, '- </b>', i['content'], "</p>") # print name and id
def test_online(self): out = StringIO.StringIO() class Counter(object): def __init__(self): self.count = 0 def call(self, hostname): self.count += 1 return self.count % 2 == 0 counter = Counter() online.main(out, counter.call, ["one", "two"]) self.assertEqual(out.getvalue(), """\ verbose "one offline" verbose "two online" set variable "ONLINE_STATUS" "ONLINE" """) out.close() self.assertEqual(counter.count, 2)
def OnSubmit(self, event): if self.ds_range.GetValue() != "" and self.n_topics.GetValue != "" and text_contents.GetValue() != "": s = self.ds_range.GetValue().split(",") n_topics = self.n_topics.GetValue() rawText = text_contents.GetValue() r1, r2 = ol.main(int(s[0]), int(s[1]), int(n_topics), rawText) print rawText self.result.SetValue(r1 + "\n" + r2)
def but1_callback(): #t=time.time() online.main() #print time.time()-t p1.destroy()
return False esng = ESpeakNG() esng.voice = 'korean' esng.say("시스템 초기화 중입니다. 약 이십초 정도 걸립니다.") i = 0 while i<20: print('Waiting for WIFI(',i+1,"s/20s)", sep='', end='\r') sleep(1) i += 1 try: if internet_on(): from actions import say print("Loading online script...") say("인공지능 서버와 연결중입니다") from online import main else: esng.say("인공지능 서버와 연결할 수 없습니다. 오프라인 모드로 전환합니다.") print("Loading offline script...") from offline import main except Exception as e: print(e) try: print("Error occured while importing. try to load offline script...") from offline import main except Exception as e: print(e) exit("Cannot import voice script") main()