Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
5736a24
Create w3-participant-workshop
Jerry2108 Jul 27, 2022
dc6744f
Update README.md
Jerry2108 Jul 27, 2022
529a986
Update README.md
Jerry2108 Jul 27, 2022
2e36dbd
Update README.md
Jerry2108 Jul 27, 2022
b61bdbd
Update README.md
Jerry2108 Jul 27, 2022
0d78ee4
Update README.md
Jerry2108 Jul 27, 2022
8cfda93
Add poll system
nonamegohst Jul 28, 2022
8679d44
Add env file
nonamegohst Jul 28, 2022
6b69f3e
Update README.md
Jerry2108 Aug 3, 2022
554135f
Update main.py
Jerry2108 Aug 3, 2022
425905c
Update README.md
Jerry2108 Aug 3, 2022
06f611d
Update README.md
Jerry2108 Aug 3, 2022
e349140
Update main.py
Jerry2108 Aug 3, 2022
700f358
Update README.md
Jerry2108 Aug 3, 2022
450c4c5
Update README.md
Jerry2108 Aug 3, 2022
b349fb7
Update README.md
Jerry2108 Aug 3, 2022
b8a075e
Update README.md
Jerry2108 Aug 3, 2022
cac907a
Update README.md
Jerry2108 Aug 3, 2022
b2917d7
Update README.md
Jerry2108 Aug 3, 2022
03d36e2
Update README.md
Jerry2108 Aug 3, 2022
071b122
Update README.md
Jerry2108 Aug 3, 2022
8c2f30b
Update README.md
Jerry2108 Aug 3, 2022
935a793
Update README.md
Jerry2108 Aug 3, 2022
f93d6ac
Update README.md
Jerry2108 Aug 10, 2022
7b2c4b3
Update README.md
Jerry2108 Aug 10, 2022
3541670
Update README.md
Jerry2108 Aug 10, 2022
f45905b
Update README.md
Jerry2108 Aug 10, 2022
95c6236
Update README.md
Jerry2108 Aug 10, 2022
3bf509f
Merge remote-tracking branch 'refs/remotes/origin/main'
Ry-DS Aug 15, 2022
142a241
put readme back
Ry-DS Aug 15, 2022
bb669a3
this needs to be fixed
Ry-DS Aug 15, 2022
389f2b4
Update README.md
Jerry2108 Aug 16, 2022
6899b93
Update README.md
Jerry2108 Aug 16, 2022
020d10c
Update README.md
Jerry2108 Aug 16, 2022
05b1556
Update README.md
Jerry2108 Aug 17, 2022
812bea7
Update README.md
Jerry2108 Aug 17, 2022
372e477
Update README.md
Jerry2108 Aug 17, 2022
ebe3a59
Update README.md
Jerry2108 Aug 17, 2022
012fbdf
Update README.md
Jerry2108 Aug 17, 2022
a4bf98f
Update README.md
Jerry2108 Aug 17, 2022
012b682
Update README.md
Jerry2108 Aug 17, 2022
6ffe554
Update README.md
Jerry2108 Aug 17, 2022
63fc659
Update README.md
Jerry2108 Aug 17, 2022
7415bf7
Update README.md
Jerry2108 Aug 17, 2022
4223d2b
Update README.md
Jerry2108 Aug 17, 2022
1dd83dd
Update README.md
Jerry2108 Aug 17, 2022
f195c0c
Update README.md
Jerry2108 Aug 17, 2022
a851bd3
Update README.md
Jerry2108 Aug 17, 2022
933a657
Update README.md
Jerry2108 Aug 17, 2022
d8b48b4
Create oldReadme.md
Jerry2108 Aug 17, 2022
2a6687e
Update poll.py
Jerry2108 Aug 18, 2022
0ee5a33
Update poll.py
Jerry2108 Aug 18, 2022
8f8d26f
Update README.md
Jerry2108 Aug 18, 2022
a2e341a
Update README.md
Jerry2108 Aug 18, 2022
6916acf
Update README.md
Jerry2108 Aug 18, 2022
d68279c
Update README.md
Jerry2108 Aug 18, 2022
49c011d
Update README.md
Jerry2108 Aug 18, 2022
f720961
Update README.md
Jerry2108 Aug 18, 2022
fbbc105
Update README.md
Jerry2108 Aug 18, 2022
0021dc3
Update README.md
Jerry2108 Aug 18, 2022
90f7191
Update README.md
Jerry2108 Aug 18, 2022
935a1ff
Update README.md
Jerry2108 Aug 18, 2022
0abed1b
Update README.md
Jerry2108 Aug 18, 2022
a9e68f8
Update README.md
Jerry2108 Aug 18, 2022
1c3e32b
Update README.md
Jerry2108 Aug 18, 2022
c6a124d
Update README.md
Jerry2108 Aug 18, 2022
938f03c
Update README.md
Jerry2108 Aug 18, 2022
d9ba01a
Update README.md
Jerry2108 Aug 18, 2022
b080747
changes to work with discord.py 2
Ry-DS Aug 26, 2022
0af8cb0
Merge branch 'main' into poll_system
Ry-DS Aug 26, 2022
d4fcfde
Merge branch 'main' into poll_system
Ry-DS Aug 26, 2022
4ce2a4c
push working code from combined
Ry-DS Aug 26, 2022
7a1eb0a
Update README.md
Jerry2108 Aug 26, 2022
6560967
Update README.md
Jerry2108 Aug 26, 2022
d92009c
Update README.md
Jerry2108 Aug 26, 2022
62b90be
Update README.md
Jerry2108 Aug 26, 2022
d4851e3
Update README.md
Jerry2108 Aug 26, 2022
29cebab
Update README.md
Jerry2108 Aug 26, 2022
7ce3731
Update README.md
Jerry2108 Aug 26, 2022
cb8751e
Update README.md
Jerry2108 Aug 26, 2022
4c27655
Update README.md
Jerry2108 Aug 26, 2022
312c126
Update README.md
Jerry2108 Aug 26, 2022
27dac3d
Update README.md
Jerry2108 Aug 26, 2022
b059415
Update README.md
Jerry2108 Aug 26, 2022
2259b0c
Update README.md
Jerry2108 Aug 26, 2022
66a9187
Update README.md
Jerry2108 Aug 26, 2022
db6aa70
Debugged chart.py
nonamegohst Aug 26, 2022
7bbcfcb
Merge branch 'poll_system' of https://github.com/HackMelbourne/Decode…
nonamegohst Aug 26, 2022
3eb71ae
Update README.md
Jerry2108 Aug 27, 2022
60dae81
Update README.md
Jerry2108 Aug 27, 2022
6ab32d1
ignore chart png
Ry-DS Aug 27, 2022
5d30461
Merge remote-tracking branch 'origin/poll_system' into poll_system
Ry-DS Aug 27, 2022
ea682a1
Update README.md
nonamegohst Aug 28, 2022
08bb038
Merge branch 'poll_system' of https://github.com/HackMelbourne/Decode…
nonamegohst Aug 28, 2022
42bbf7b
Merge branch 'main' into poll_system
Ry-DS Aug 29, 2022
fe6f57f
Minor update to create_bar_chart
nonamegohst Aug 29, 2022
1be5600
Update README.md
nonamegohst Aug 29, 2022
2106cb0
Updated bar chart task
nonamegohst Aug 30, 2022
38ee6c1
Fixed chart and added time error
nonamegohst Aug 30, 2022
c289aeb
Move to w3
Ry-DS Sep 4, 2022
bb1b019
Merge branch 'main' into poll_system
Ry-DS Sep 4, 2022
39ee646
Update README.md
Jerry2108 Sep 6, 2022
5244798
Update README.md
Jerry2108 Sep 6, 2022
7993d4c
Update README.md
nonamegohst Sep 6, 2022
4f5c63f
Merge branch 'poll_system' of https://github.com/HackMelbourne/Decode…
nonamegohst Sep 6, 2022
3902671
Updated bar graph task
nonamegohst Sep 7, 2022
0a7c56c
Added tally code to bar graph task
nonamegohst Sep 7, 2022
5e1ec8f
Add bar chart task to Table of Contents
nonamegohst Sep 7, 2022
a11df4f
Minor fix to README.md
nonamegohst Sep 7, 2022
975eb92
Update README.md
Jerry2108 Sep 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

*.pyc
/logs/


chart.png
50 changes: 50 additions & 0 deletions EmojiCollection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import emoji
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


class EmojiCollection():
def __init__(self):

options = Options()
# TODO this can't be OS specific
# options.binary_location = "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta"
options.binary_location = "C:\Program Files\Google\Chrome\Application\chrome.exe"

self.driver = webdriver.Chrome(options=options)
self.driver.get("https://emojipedia.org")
# accepts cookies
acceptCookies = WebDriverWait(
self.driver,
30).until(EC.presence_of_element_located((By.ID, "onetrust-accept-btn-handler"))).click()

def searchEngineReturned(self):
#click onto the link of the first emoji
clickFirstEmoji = WebDriverWait(self.driver, 30).until(
EC.element_to_be_clickable((By.XPATH, "/html/body/div[@class='container']/div[@class='content']/ol/*[1]/h2/a"))).click()
def getEmoji(self):
try:
nameOfEmoji = WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "span.shortcode"))).text
return emoji.emojize(nameOfEmoji)
except selenium.common.exceptions.TimeOutException:
tmp = emoji.emojize(":red_heart:")
return tmp
#enter the requested emoji to the search engine
def search(self, emoji):
#type a key word to the search engine
element = self.driver.find_element(By.ID, "id_q")
element.send_keys(emoji)
#the search engine starts searching
element.send_keys(Keys.RETURN)
self.searchEngineReturned()
return self.getEmoji()

def quit(self):
self.driver.quit()

13 changes: 13 additions & 0 deletions Server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import http.server
import socketserver
import os
from dotenv import load_dotenv

load_dotenv()
def runServer():
Handler = http.server.SimpleHTTPRequestHandler
port = os.environ.get('PORT')
with socketserver.TCPServer(("", int(port)), Handler) as httpd:
print(f'serving at port {port}')
httpd.serve_forever()

Binary file added __pycache__/EmojiCollection.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/Server.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/nltk.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/poll.cpython-310.pyc
Binary file not shown.
Binary file added chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)


plt.rcdefaults()
fig, ax = plt.subplots()
# Example data
people = ['Tom', 'Dick', 'Harry', 'Slim', 'Jim']
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))

ax.barh(y_pos, performance, xerr=error, align='center')
ax.set_yticks(y_pos)
ax.set_yticklabels(people)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel('Performance')
ax.set_title('How fast do you want to go today?')


plt.savefig('chart.png')
File renamed without changes.
81 changes: 81 additions & 0 deletions cogs/poll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from ast import alias
import discord
import asyncio
import matplotlib.pyplot as plt
import numpy as np
from discord.ext import commands
import emoji


class Poll(commands.Cog):
def __init__(self, bot):
self.bot = bot

async def create_bar_chart(self, options, reactions, question):
totalVotes = 0
votes = []

#calculate the number of votes for each option
for reaction in reactions:
# Start at -1 to exclude the vote of the bot
v = -1

async for _ in reaction.users():
v += 1

totalVotes += v
votes.append(v)

# Calculates percentage of votes for each option
percentages = [round((vote/totalVotes)* 100, 2) for vote in votes]

# Initialises the figure
fig, ax = plt.subplots()
y_pos = np.arange(len(options))
ax.barh(y_pos, percentages, align='center')
ax.set_yticks(y_pos, labels=options)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel('Votes (%)')
ax.set_title(question)
plt.savefig('chart.png')


@commands.command(aliases=["p"])
async def init_poll(self, ctx, question, time, *options):
# Prevents user from inputting more than 3 options
if len(options) > 3:
await ctx.send("The number of options cannot exceed the allowed limit")
return
if not time.isdigit():
await ctx.send("Time has to be a digit")
return

embed = discord.Embed(title = question,
description= f'Poll will end in {time} seconds :alarm_clock:. There are {len(options)} options:')
tmp = [':one:', ':two:', ':three:'][:len(options)]
emojis = [emoji.emojize(e, language='alias') for e in tmp]
for i in range(len(options)):
emo = emojis[i]
embed.add_field(name = emo, value = options[i], inline = True)
embed.add_field(name="Instructions", value="React to cast a vote", inline=False)
embed.set_footer(text = f'This poll is created by {ctx.author.name}')
poll = await ctx.send(embed = embed)

# add emojis as reactions to the poll
for emo in emojis:
await poll.add_reaction(emo)
await asyncio.sleep(int(time))

#calculate the result of the poll
message = await ctx.fetch_message(poll.id)

# create a bar chart as a result
await self.create_bar_chart(options, message.reactions, question)
result = discord.Embed(title='Result', description = "Here are the vote results")
file = discord.File("chart.png")
result.set_image(url="attachment://chart.png")
await ctx.send(file=file, embed = result)


async def setup(bot):
await bot.add_cog(Poll(bot))
Loading