mirror of
https://github.com/Yawn-Wider/YWPolarisVore.git
synced 2026-07-17 11:05:48 +01:00
7c8bb85de3
* Update settings * Whitespace changes * Comment out merger hooks in gitattributes Corrupt maps would have to be resolved in repo before hooks could be updated * Revert "Whitespace changes" This reverts commit afbdd1d8442973f5d570c30920d9d865b5acd479. * Whitespace again minus example * Gitignore example changelog * Restore changelog merge setting * Keep older dmi hook attribute until hooks can be updated * update vscode settings too * Renormalize remaining * Revert "Gitignore example changelog" This reverts commit de22ad375d3ee4d5930c550da2fd23a29a86e616. * Attempt to normalize example.yml (and another file I guess) * Try again
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from urllib2 import urlopen
|
|
from json import loads
|
|
from pickle import dump,load
|
|
from CORE_DATA import no_absolute_paths
|
|
def xkcd(link):
|
|
try:
|
|
filename = link[link.find("xkcd.com")+9:].replace("/","").replace("\\","")
|
|
if no_absolute_paths:
|
|
tiedosto = open("xkcdcache/"+filename,"r")
|
|
else:
|
|
tiedosto = open(directory+"xkcdcache/"+filename,"r")
|
|
except:
|
|
try:
|
|
if no_absolute_paths:
|
|
tiedosto = open("xkcdcache/"+filename,"w")
|
|
else:
|
|
tiedosto = open(directory+"xkcdcache/"+filename,"w")
|
|
except IOError:
|
|
return "NOTHING"
|
|
else:
|
|
try:
|
|
return load(tiedosto)
|
|
except EOFError:
|
|
tiedosto = open("xkcdcache/"+filename,"w")
|
|
pass #Corrupt cache, moving on.
|
|
if link[-1] == "/" or link[-1] == "\\": #Ending is fine.
|
|
link += "info.0.json"
|
|
else:
|
|
link += "/info.0.json"
|
|
try:
|
|
data = urlopen(link).read()
|
|
except:
|
|
return "NOTHING"
|
|
try:
|
|
newdata = loads(data)["title"]
|
|
dump(newdata,tiedosto)
|
|
return newdata
|
|
except:
|
|
return "NOTHING"
|
|
|