-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added swdc headers and removed ping calls
- Loading branch information
Showing
16 changed files
with
195 additions
and
148 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import time as timeModule | ||
import platform | ||
import json | ||
import os | ||
|
||
from .Constants import * | ||
from datetime import * | ||
|
||
def getUtcOffset(): | ||
timestamp = timeModule.time() | ||
time_local = datetime.fromtimestamp(timestamp) | ||
time_utc = datetime.utcfromtimestamp(timestamp) | ||
offset_in_sec = round((time_local - time_utc).total_seconds()) | ||
return offset_in_sec | ||
|
||
def getNowTimes(): | ||
nowInSec = round(timeModule.time()) | ||
offsetInSec = getUtcOffset() | ||
localNowInSec = round(nowInSec + offsetInSec) | ||
day = datetime.now().date().isoformat() | ||
return { | ||
'nowInSec': nowInSec, | ||
'localNowInSec': localNowInSec, | ||
'offsetInSec': offsetInSec, | ||
'day': day | ||
} | ||
|
||
def getIsNewDay(): | ||
day = getNowTimes()['day'] | ||
currentDay = getItem('currentDay') | ||
if (currentDay != day): | ||
return True | ||
else: | ||
return False | ||
|
||
def getOs(): | ||
system = platform.system() | ||
return system | ||
|
||
def getTimezone(): | ||
myTimezone = None | ||
try: | ||
myTimezone = datetime.now(timezone.utc).astimezone().tzname() | ||
except Exception: | ||
pass | ||
return myTimezone | ||
|
||
def getPluginId(): | ||
return PLUGIN_ID | ||
|
||
def getVersion(): | ||
packageJson = os.path.join(os.path.dirname(__file__), '..', 'package.json') | ||
version = "2.2.1" | ||
try: | ||
with open(packageJson) as jsonData: | ||
loadedJsonData = json.load(jsonData) | ||
version = loadedJsonData.get("version", "2.2.1") | ||
except Exception as ex: | ||
print("Error reading package info: %s" % ex) | ||
|
||
return version | ||
|
||
def getPluginName(): | ||
pluginName = __name__.split('.')[0] | ||
return pluginName | ||
|
||
# fetch a value from the .software/session.json file | ||
def getItem(key): | ||
jsonObj = getSoftwareSessionAsJson() | ||
|
||
# return a default of None if key isn't found | ||
val = jsonObj.get(key, None) | ||
|
||
return val | ||
|
||
# get an item from the session json file | ||
def setItem(key, value): | ||
jsonObj = getSoftwareSessionAsJson() | ||
jsonObj[key] = value | ||
|
||
content = json.dumps(jsonObj) | ||
|
||
sessionFile = getSoftwareSessionFile() | ||
with open(sessionFile, 'w') as f: | ||
f.write(content) | ||
|
||
def getSoftwareSessionAsJson(): | ||
try: | ||
with open(getSoftwareSessionFile()) as sessionFile: | ||
loadedSessionFile = json.load(sessionFile) | ||
return loadedSessionFile | ||
except Exception: | ||
return {} | ||
|
||
def getSoftwareSessionFile(): | ||
file = getSoftwareDir(True) | ||
return os.path.join(file, 'session.json') | ||
|
||
def getSoftwareDir(autoCreate): | ||
softwareDataDir = os.path.expanduser('~') | ||
softwareDataDir = os.path.join(softwareDataDir, '.software') | ||
if (autoCreate is True): | ||
os.makedirs(softwareDataDir, exist_ok=True) | ||
return softwareDataDir | ||
|
||
|
||
|
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Oops, something went wrong.