Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #12 from ExtraRandom/master
Browse files Browse the repository at this point in the history
Multiple Changes
  • Loading branch information
David Jetelina authored and David Jetelina committed May 22, 2016
2 parents 7856730 + e50ddf7 commit 1a40c64
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
28 changes: 21 additions & 7 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def facebook(self):
data = await resp.json()

msg1 = data["data"][0]["message"]
y,m,d, = date_split(data["data"][0]["created_time"]) # y = year, m = month, d = day
y, m, d, = date_split(data["data"][0]["created_time"]) # y = year, m = month, d = day

msg = "**Latest Facebook Post**\n" \
"**Posted:** {}{} of {}, {}.\n\n" \
Expand All @@ -89,7 +89,7 @@ async def youtube(self):
async with session.get('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC0YagOInbZx'
'j10gaWwb1Nag&maxResults=1&order=date&key={}'.format(t.yt_key)) as resp:
data = await resp.json()
channel = "https://www.youtube.com/c/idiotechgaming"
# channel = "https://www.youtube.com/c/idiotechgaming"

mo = "**" # Modifier (e.g. * for italic, ** for bold, __ for underline and so on)
title = mo + "Latest Upload: " + mo\
Expand All @@ -101,11 +101,10 @@ async def youtube(self):
month = calendar.month_name[int(month)] # takes month number and returns word form (i.e. 05 = may)

uploaded = mo + "Uploaded: " + mo + "{} the {}{}, {}.".format(month, day, get_date_suf(day), year)
# link = "```https://youtu.be/" + data["items"][0]["id"]["videoId"] + "```"
link = "https://youtu.be/" + data["items"][0]["id"]["videoId"]
# uses ``` to stop video from being embed

await s.destructmsg(title + "\n" + uploaded + "\n\n"+channel, 30, self.bot)

await s.destructmsg(title + "\n" + uploaded + "\n\n"+link, 30, self.bot)

@commands.command(description=desc.rules, brief=desc.rules)
async def rules(self):
Expand Down Expand Up @@ -190,7 +189,12 @@ async def release(self, ctx):
for game in self.dates:
if game.lower().startswith(arg.lower()) or game.lower() is arg.lower():
days, hrs, mins = calc_until(self.dates[game])
msg = "{} releases in {},{} hours and {} minutes.".format(game, days, hrs, mins)
msg = "Error in command 'release', string 'msg' not changed."
# ^^ if for some reason the below code doesnt set the message properly
if int_day(days) < 0: # if hours is a minus (i.e. game is released)
msg = "{} is out now!".format(game)
else:
msg = "{} releases in {},{} hours and {} minutes.".format(game, days, hrs, mins)
await s.destructmsg(msg, 30, self.bot)

break
Expand All @@ -206,12 +210,22 @@ async def release(self, ctx):
await s.destructmsg("```{}```".format(msg), 30, self.bot)


def int_day(day):
"""
Takes day as string ('3 days') and returns just the number as an integer
:param day:
:return:
"""
day, word = day.split(" ")
return int(day)


def get_date_suf(day):
# Get the suffix to add to date ('st' for 1, 'nd' for 2 and so on) code from http://stackoverflow.com/a/5891598
if 4 <= int(day) <= 20 or 24 <= int(day) <= 30:
suffix = "th"
else:
suffix = ["st", "nd", "rd"][day % 10 - 1]
suffix = ["st", "nd", "rd"][int(day) % 10 - 1]
return suffix


Expand Down
2 changes: 1 addition & 1 deletion cogs/restricted.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def nick(self, ctx, *, nick: str):
@checks.mod_or_permissions(manage_messages=True)
async def rtfh(self, ctx, target: str, cmd: str):
"""
RTFH stands for reat the F***ing help
RTFH stands for read the F***ing help
Not using @commands.group because we want to have one command for both commands and subcommands
Expand Down
9 changes: 4 additions & 5 deletions cogs/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ def __init__(self, bot):
self.base_url = "http://api.openweathermap.org/data/2.5/weather?q=" # base url (before query and key)
self.a_url = "&appid=" # additional url (comes after query and before key)

@commands.command(passcontext=True, description="Weather", brief="Weather")
@commands.command(passcontext=True, description="Get Weather Status in <loc> (a given city name)",
brief="Finds Weather Status for input city")
async def weather(self, *, loc: str): # loc = location
spaces = ' ' in loc # checks if there is spaces in given text - False = No Spaces
# print(spaces) # debug - remove
if not spaces:
await s.destructmsg("***Getting Weather Status for {}. This make take a while.***".format(loc), 15, self.bot)
await s.destructmsg("***Getting Weather Status for {}. This may take a while.***".format(loc), 15, self.bot)
# seems to take around 15 seconds to find weather information

weather_api = self.base_url + loc + self.a_url + self.key
# print(weather_api)

with aiohttp.ClientSession() as session:
async with session.get(weather_api)as resp:
data = await resp.json()
# print(data)

temp = data["main"]["temp"]
brief = data["weather"][0]["main"] # ie cloudy
desc = data["weather"][0]["description"] # ie very cloudy/ overcast clouds and so on
Expand Down

0 comments on commit 1a40c64

Please sign in to comment.