Skip to content

Instantly share code, notes, and snippets.

@danieltharp
Created April 11, 2019 00:22
Show Gist options
  • Save danieltharp/6c332754189d64f835db3cc6a4f13579 to your computer and use it in GitHub Desktop.
Save danieltharp/6c332754189d64f835db3cc6a4f13579 to your computer and use it in GitHub Desktop.
from xmlrpclib import ServerProxy
import datetime
from time import sleep
from collections import OrderedDict
today = datetime.datetime.now()
DD = datetime.timedelta(days=7)
earlier = today - DD
idate = earlier.strftime("%Y-%m-%d")
s = ServerProxy('https://user:apikey@www.wikidot.com/xml-rpc-api.php')
dic={}
articlelist = s.pages.select({"site": "scp-wiki", "tags_any": ["scp"], "order": "created_at desc"})
sleep(0.3) # obey wikidot API limits
while True:
article = articlelist.pop(0)
article = article.split()
meta = s.pages.get_meta({"site": "scp-wiki", "pages": article})
sleep(0.3) # obey wikidot API limits
key = meta.keys()
key = ''.join(key)
createdat = meta[key]['created_at']
thedate = createdat[0:10]
articledate = datetime.datetime.strptime(thedate, "%Y-%m-%d")
comparedate = datetime.datetime.strptime(idate, "%Y-%m-%d")
if articledate < comparedate:
break
else:
dic.update(meta)
dic = OrderedDict(sorted(dic.items(), key=lambda x: x[1]['rating'],reverse = True))
otw = ""
text = "#SCPs:\n\nRank|Entry|Score|Author\n:---|:---|:--:|:---\n"
rank = 1
for i in dic:
text = text + "\#" + str(rank) + "|[" + dic[i]['title'] + "](http://www.scp-wiki.net/" + dic[i]['fullname'] + ")|"
if dic[i]['rating'] >= 50:
text = text + "*"
if dic[i]['rating'] >= 75:
text = text + "*"
if dic[i]['rating'] >= 100:
text = text + "*"
text = text + "+" + str(dic[i]['rating'])
if dic[i]['rating'] >= 50:
text = text + "*"
if dic[i]['rating'] >= 75:
text = text + "*"
if dic[i]['rating'] >= 100:
text = text + "*"
text = text + "|[" + dic[i]['created_by'] + "](http://www.wikidot.com/user:info/" + dic[i]['created_by'] + ")\n"
if rank == 1:
otw = otw + "#SCP Of The Week:\n\n#[" + dic[i]['title'] + "](http://www.scp-wiki.net/" + dic[i]['fullname'] + ")\n\n"
rank += 1
text = text + "\n\n"
dic={}
articlelist = s.pages.select({"site": "scp-wiki", "tags_any": ["tale"], "order": "created_at desc"})
sleep(0.3) # obey wikidot API limits
while True:
article = articlelist.pop(0)
article = article.split()
meta = s.pages.get_meta({"site": "scp-wiki", "pages": article})
sleep(0.3) # obey wikidot API limits
key = meta.keys()
key = ''.join(key)
createdat = meta[key]['created_at']
thedate = createdat[0:10]
articledate = datetime.datetime.strptime(thedate, "%Y-%m-%d")
comparedate = datetime.datetime.strptime(idate, "%Y-%m-%d")
if articledate < comparedate:
break
else:
dic.update(meta)
dic = OrderedDict(sorted(dic.items(), key=lambda x: x[1]['rating'],reverse = True))
text = text + "#Tales:\n\nRank|Entry|Score|Author\n:---|:---|:--:|:---\n"
rank = 1
for i in dic:
text = text + "\#" + str(rank) + "|[" + dic[i]['title'] + "](http://www.scp-wiki.net/" + dic[i]['fullname'] + ")|"
if dic[i]['rating'] >= 50:
text = text + "*"
if dic[i]['rating'] >= 75:
text = text + "*"
if dic[i]['rating'] >= 100:
text = text + "*"
text = text + "+" + str(dic[i]['rating'])
if dic[i]['rating'] >= 50:
text = text + "*"
if dic[i]['rating'] >= 75:
text = text + "*"
if dic[i]['rating'] >= 100:
text = text + "*"
text = text + "|[" + dic[i]['created_by'] + "](http://www.wikidot.com/user:info/" + dic[i]['created_by'] + ")\n"
if rank == 1:
otw = otw + "#Tale Of The Week:\n\n#[" + dic[i]['title'] + "](http://www.scp-wiki.net/" + dic[i]['fullname'] + ")\n\n"
rank += 1
text = text + "\n\n" + otw
textfile = open('ratings.txt', 'w')
textfile.write(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment