bunch'o'stuff
This commit is contained in:
parent
2fa3a5a015
commit
fb08870f4a
3 changed files with 15 additions and 11 deletions
|
@ -5,6 +5,8 @@ import re
|
||||||
|
|
||||||
db_ready = False
|
db_ready = False
|
||||||
|
|
||||||
|
CAN_DOWNVOTE = False
|
||||||
|
|
||||||
|
|
||||||
def db_init(db):
|
def db_init(db):
|
||||||
db.execute("""CREATE TABLE if not exists karma(
|
db.execute("""CREATE TABLE if not exists karma(
|
||||||
|
@ -92,7 +94,7 @@ def karma_add(match, nick='', chan='', db=None, notice=None):
|
||||||
total_karma) values(?,?,?,?)""", (nick_vote.lower(), 0, 0, 0))
|
total_karma) values(?,?,?,?)""", (nick_vote.lower(), 0, 0, 0))
|
||||||
up(db, nick_vote)
|
up(db, nick_vote)
|
||||||
notice("Gave {} 1 karma!".format(nick_vote))
|
notice("Gave {} 1 karma!".format(nick_vote))
|
||||||
if match.group(2) == '--':
|
if match.group(2) == '--' and CAN_DOWNVOTE:
|
||||||
db.execute("""INSERT or IGNORE INTO karma(
|
db.execute("""INSERT or IGNORE INTO karma(
|
||||||
nick_vote,
|
nick_vote,
|
||||||
up_karma,
|
up_karma,
|
||||||
|
|
|
@ -37,9 +37,9 @@ def wolframalpha(inp, bot=None):
|
||||||
if subpod:
|
if subpod:
|
||||||
results.append(subpod)
|
results.append(subpod)
|
||||||
if results:
|
if results:
|
||||||
pod_texts.append(title + ': ' + ', '.join(results))
|
pod_texts.append(title + u': ' + u', '.join(results))
|
||||||
|
|
||||||
ret = ' - '.join(pod_texts)
|
ret = u' - '.join(pod_texts)
|
||||||
|
|
||||||
if not pod_texts:
|
if not pod_texts:
|
||||||
return 'No results.'
|
return 'No results.'
|
||||||
|
@ -56,4 +56,4 @@ def wolframalpha(inp, bot=None):
|
||||||
if not ret:
|
if not ret:
|
||||||
return 'No results.'
|
return 'No results.'
|
||||||
|
|
||||||
return "{} - {}".format(ret, short_url)
|
return u"{} - {}".format(ret, short_url)
|
||||||
|
|
|
@ -14,7 +14,7 @@ video_url = "http://youtu.be/%s"
|
||||||
|
|
||||||
|
|
||||||
def plural(num=0, text=''):
|
def plural(num=0, text=''):
|
||||||
return "%d %s%s" % (num, text, "s"[num==1:])
|
return "{:,} {}{}".format(num, text, "s"[num==1:])
|
||||||
|
|
||||||
|
|
||||||
def get_video_description(video_id):
|
def get_video_description(video_id):
|
||||||
|
@ -25,7 +25,7 @@ def get_video_description(video_id):
|
||||||
|
|
||||||
data = request['data']
|
data = request['data']
|
||||||
|
|
||||||
out = '\x02%s\x02' % data['title']
|
out = '\x02{}\x02'.format(data['title'])
|
||||||
|
|
||||||
if not data.get('duration'):
|
if not data.get('duration'):
|
||||||
return out
|
return out
|
||||||
|
@ -39,6 +39,7 @@ def get_video_description(video_id):
|
||||||
out += "%ds\x02" % (length % 60)
|
out += "%ds\x02" % (length % 60)
|
||||||
|
|
||||||
if 'ratingCount' in data:
|
if 'ratingCount' in data:
|
||||||
|
# format
|
||||||
likes = plural(int(data['likeCount']), "like")
|
likes = plural(int(data['likeCount']), "like")
|
||||||
dislikes = plural(data['ratingCount'] - int(data['likeCount']), "dislike")
|
dislikes = plural(data['ratingCount'] - int(data['likeCount']), "dislike")
|
||||||
|
|
||||||
|
@ -47,7 +48,8 @@ def get_video_description(video_id):
|
||||||
dislikes, percent)
|
dislikes, percent)
|
||||||
|
|
||||||
if 'viewCount' in data:
|
if 'viewCount' in data:
|
||||||
out += ' - \x02%s\x02 views' % format(data['viewCount'], ",d")
|
views = data['viewCount']
|
||||||
|
out += ' - \x02{:,}\x02 view{}'.format(views, "s"[views==1:])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
uploader = http.get_json(base_url + "users/{}?alt=json".format(data["uploader"]))["entry"]["author"][0]["name"]["$t"]
|
uploader = http.get_json(base_url + "users/{}?alt=json".format(data["uploader"]))["entry"]["author"][0]["name"]["$t"]
|
||||||
|
@ -55,7 +57,7 @@ def get_video_description(video_id):
|
||||||
uploader = data["uploader"]
|
uploader = data["uploader"]
|
||||||
|
|
||||||
upload_time = time.strptime(data['uploaded'], "%Y-%m-%dT%H:%M:%S.000Z")
|
upload_time = time.strptime(data['uploaded'], "%Y-%m-%dT%H:%M:%S.000Z")
|
||||||
out += ' - \x02%s\x02 on \x02%s\x02' % (uploader,
|
out += ' - \x02{}\x02 on \x02{}\x02'.format(uploader,
|
||||||
time.strftime("%Y.%m.%d", upload_time))
|
time.strftime("%Y.%m.%d", upload_time))
|
||||||
|
|
||||||
if 'contentRating' in data:
|
if 'contentRating' in data:
|
||||||
|
|
Reference in a new issue