Last active
January 6, 2019 11:21
Revisions
-
kde713 revised this gist
Jan 6, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,7 +40,7 @@ def sync(self): win32api.SetSystemTime(server_time.year, server_time.month, server_time.isocalendar()[2], server_time.day, server_time.hour, server_time.minute, server_time.second, 0) else: raise SyncError("Not supported platform: " + str(sys.platform)) if __name__ == "__main__": -
kde713 revised this gist
Jan 6, 2019 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +0,0 @@ -
kde713 renamed this gist
Jan 6, 2019 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,13 +27,13 @@ def get_api_datetime(self, tz: str) -> datetime: class TimeSyncApplication: def view(self): client = WorldTimeApiClient() sys.stdout.write(client.get_api_datetime("UTC").isoformat()) def sync(self): client = WorldTimeApiClient() server_time = client.get_api_datetime("UTC") if sys.platform == "win32": from win32 import win32api -
kde713 created this gist
Jan 6, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ import sys from datetime import datetime import fire import requests class SyncError(Exception): def __init__(self, message): self.message = message def __str__(self): return self.message def __repr__(self): return f"SyncError('{self.message}')" class WorldTimeApiClient: def get_api_datetime(self, tz: str) -> datetime: response = requests.get("http://worldtimeapi.org/api/timezone/" + tz) data = response.json() if data.get("error"): raise SyncError("API Error: " + response.json()['error']) return datetime.fromisoformat(response.json()['datetime']) class TimeSyncApplication: def view(self, tz: str): client = WorldTimeApiClient() sys.stdout.write(client.get_api_datetime(tz).isoformat()) def sync(self, tz: str): client = WorldTimeApiClient() server_time = client.get_api_datetime(tz) if sys.platform == "win32": from win32 import win32api win32api.SetSystemTime(server_time.year, server_time.month, server_time.isocalendar()[2], server_time.day, server_time.hour, server_time.minute, server_time.second, 0) else: raise SyncError("Now supported platform: " + str(sys.platform)) if __name__ == "__main__": fire.Fire(TimeSyncApplication) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ pywin32==224 requests==2.21.0 fire==0.1.3