Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- from pprint import pprint
- from pytz import timezone
- from datetime import datetime, timedelta, tzinfo
- from tzlocal import get_localzone
- import pytz
- import time
- import math
- #Time stuffs
- class FixedOffset(tzinfo):
- def __init__(self, offset):
- hours = int(offset[1:-2])
- minutes = int(offset[-2:])
- if(offset[:1] == '-'):
- hours = 0 - hours
- minutes = 0 - minutes
- self.__offset = timedelta(hours=hours, minutes=minutes)
- self.__dst = timedelta(hours=hours-1, minutes=minutes)
- def utcoffset(self, dt):
- return self.__offset
- def dst(self, dt):
- return self.__dst
- def formatTimeleft(delta):
- days = delta.days
- months = 0
- # if days > 31:
- # days = days % 31
- # months = days / 31
- if days == 1:
- daystr = 'day'
- else:
- daystr = 'days'
- # if months == 0:
- return str(days) + ' Days'
- # else:
- # return str(math.ceil(months)) + ' Month, ' + str(days) + ' Days'
- def getDurationstr():
- eastern = timezone('EST')
- releaseTimestamp = datetime(2014, 9, 23, 21, 0, 0)# 23/09/2014 9:00PM
- releaseLocalized = eastern.localize(releaseTimestamp)
- offset = datetime.now(eastern).strftime('%z')
- now = datetime.now(FixedOffset(offset))
- timeLeft = releaseLocalized - now
- return formatTimeleft(timeLeft)
- BOT_START = '[](#SHIELDBOTSTART)'
- BOT_END = '[](#SHIELDBOTEND)'
- #User Login
- USER = {
- 'username': 'SHIELD_countdown_bot',
- 'password': 'LOLNOPE'
- }
- ##Reddit Login
- r = praw.Reddit(user_agent='Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36', disable_update_check=True)
- r.config._ssl_url = None
- r.login(USER['username'], USER['password'])
- page = r.get_wiki_page('shield', 'config/sidebar')
- content = page.content_md
- bot_start_loc = content.find(BOT_START)
- bot_end_loc = content.find(BOT_END)
- string_before = content[:bot_start_loc] + BOT_START
- string_after = content[bot_end_loc:]
- countdown_content = '\n**Agents of SHIELD Season 2 Starts in:**\n# **' + getDurationstr() + '**\n'
- new_page = string_before + countdown_content + string_after
- r.edit_wiki_page('shield', 'config/sidebar', new_page, 'Testing Reasons')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement