From e8e6f10366b9b31c0ca1058bd280a5c671a14543 Mon Sep 17 00:00:00 2001 From: skyspook Date: Fri, 3 Apr 2020 21:29:45 -0500 Subject: [PATCH] Add wikipedia history from member number --- bot.py | 15 ++++++++++++++- history.py | 27 +++++++++++++++++++++++++++ requirements.txt | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 history.py diff --git a/bot.py b/bot.py index 2c6f6c5..c0f6864 100755 --- a/bot.py +++ b/bot.py @@ -6,6 +6,7 @@ from functions import * from discord.ext import commands from datetime import datetime +from history import get_wiki_history bot = commands.Bot(command_prefix="!", case_insensitive=True, help_command=None) @@ -162,7 +163,19 @@ async def members(ctx): return total = (await resp.json(content_type='text/html'))['total'] reply = f"There are currently {total} members." - await ctx.send(reply) + embed = None + try: + + hist = get_wiki_history(total) + embed = discord.Embed( + color = 3447003, + description = hist, + title = 'Mitch History', + url = 'https://en.wikipedia.org/wiki/' + str(total) + "#Events") + except: + pass + + await ctx.send(content = reply, embed = embed) return @bot.command() diff --git a/history.py b/history.py new file mode 100644 index 0000000..3969f5c --- /dev/null +++ b/history.py @@ -0,0 +1,27 @@ +import wikipediaapi +import random + +def get_wiki_history(year): + year = str(year) + wiki_wiki = wikipediaapi.Wikipedia('en') + + page_py = wiki_wiki.page(year) + for s in page_py.sections: + if s.title == 'Events': + my_section = s + if( len(s.sections) > 0 ): + my_section = random.choice(s.sections) + events = my_section.text.split('\n') + i = random.randrange(0,len(events)) + while(not events[i].lower().startswith( ('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'))): + i = random.randrange(0,len(events)) + + result = events[i] + + if( len(events[i]) < 15 ): + result = result + ' ' + events[i+1] + elif( ): + result = result[i-1] + ' ' + result + + return year + ' - ' + result + return "Nothin happened in " + year \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 83fd135..0707656 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ websockets>=6.0,<7.0 PyYAML requests Pillow +wikipedia-api #See readme for installation instructions discord.py>=1.1.0a