diff options
| author | jwanek <eddie.atten.ea29@gmail.com> | 2020-05-23 21:18:56 +0100 | 
|---|---|---|
| committer | jwanek <eddie.atten.ea29@gmail.com> | 2020-05-23 21:18:56 +0100 | 
| commit | 8de537dc2e4c88aabaccd5e775be9a8d8f13e9e5 (patch) | |
| tree | 869927bca598f4d5f1cfcad91ba907c7649338b2 | |
| parent | 2892772ab0ba11dcf562e9fd3a9faf711b384e78 (diff) | |
| download | SmallYTChannelBot-8de537dc2e4c88aabaccd5e775be9a8d8f13e9e5.tar.gz SmallYTChannelBot-8de537dc2e4c88aabaccd5e775be9a8d8f13e9e5.zip | |
added medals system, improved logging
| -rwxr-xr-x | misc_classes.py | 12 | ||||
| -rwxr-xr-x | subreddit.py | 33 | 
2 files changed, 26 insertions, 19 deletions
| diff --git a/misc_classes.py b/misc_classes.py deleted file mode 100755 index 6d310b3..0000000 --- a/misc_classes.py +++ /dev/null @@ -1,12 +0,0 @@ -import os - -class SimpleLogger: -    def __init__(self): -        if not os.path.exists("actions.log"): -            file = open("actions.log", "w") -            file.close() - -    def log(self, message): -        file = open("actions.log", "a") -        file.write("%s\n" % message) -        file.close()
\ No newline at end of file diff --git a/subreddit.py b/subreddit.py index 3743a8d..4afe77a 100755 --- a/subreddit.py +++ b/subreddit.py @@ -1,8 +1,8 @@ -from misc_classes import SimpleLogger  from imgurpython import ImgurClient  from operator import itemgetter  from database import Database  import datetime +import logging  import ytapi  import graph  import time @@ -22,16 +22,21 @@ FREE_FLAIRS = CONFIG["free_flairs"]  IMGUR = ImgurClient(**CONFIG["imgurapi"])  db = Database() -simplelogger = SimpleLogger() + +logging.basicConfig(  +    format = "[%(asctime)s] %(message)s",  +    level = logging.INFO, +    handlers=[ +        logging.FileHandler("actions.log"), +        logging.StreamHandler() +    ])  def get_time():      #this is not the correct way to do this but I don't care      return time.strftime("%b %d %Y %H:%M:%S", time.gmtime())  def display(message): -    message = "%d\t[%s]\t%s" % (os.getpid(), get_time(), message) -    print(message) -    simplelogger.log(message) +    logging.info(message)  def get_lambda_from_flair(s):      result = re.search("\[(.*)\]", s) @@ -44,6 +49,18 @@ def update_users_flair_from_comment(comment):      #implemented only for legacy      update_users_flair(str(comment.author)) +def get_medal(actualscore): +    if actualscore >= 10 and actualscore < 25: +        return "🥉 Bronze " +    elif actualscore >= 25 and actualscore < 50: +        return "🥈 Silver " +    elif actualscore >= 50 and actualscore < 100: +        return "🥇 Gold " +    elif actualscore > 100: +        return "🏆 Platinum " +    else: +        return "" +  def update_users_flair(username):      flairtext = next(SUBREDDIT.flair(redditor=username))["flair_text"]      if flairtext is None: @@ -52,10 +69,12 @@ def update_users_flair(username):          flairscore = get_lambda_from_flair(flairtext)          flairtext = str(flairtext.replace("[%s] " % flairscore, ""))      if username in get_mods(): -        newflair = "[∞λ] %s" % (flairtext) +        newflair = "[🏆 ∞λ] %s" % (flairtext)      else:          actualscore = db.get_lambda(username)[0] -        newflair = "[%iλ] %s" % (actualscore, flairtext) +        newflair = "[%s%iλ] %s" % (get_medal(actualscore), actualscore, flairtext) + +    logging.info("/u/%s had their flair updated" % username)      SUBREDDIT.flair.set(redditor = username, text = newflair)  def get_mods(): | 
