Skip to content

Commit

Permalink
App uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
federicocanedo committed Sep 16, 2022
0 parents commit 687742b
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 0 deletions.
181 changes: 181 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
*~

config.py

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://mrkandreev.name/snippets/gitignore-generator/#Linux,Python,Windows
1 change: 1 addition & 0 deletions config.py.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BOTTOKEN = "yourtokenhere"
87 changes: 87 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/python3.9

import time, json, requests, config, discord, asyncio
from discord.ext import commands
from bs4 import BeautifulSoup
from datetime import datetime

intents = discord.Intents.default()
intents.members = True
taxArg = 1.75
currencies = {}

bot = commands.Bot(command_prefix="!", intents=intents)


@bot.event
async def on_ready():
print("Bot listo")
getCurrencies()

def getGameWithName(name):
response = requests.get(f'https://store.steampowered.com/search/?category1=998&term={name}')
soup = BeautifulSoup(response.content, "html.parser")

try:
gameid = soup.find(id="search_resultsRows").findChildren("a" , recursive=False)[0]['href'].split('/')[4]
return gameid
except:
return None

def getCurrencies():
global currencies
response = requests.get('https://www.prexcard.com/hacelabien')
soup = BeautifulSoup(response.content, "html.parser")

print(f"UY {soup.find(id='cotizacionUy')['value']}")
print(f"AR {soup.find(id='cotizacionArg')['value']}")
now = datetime.now()

currencies['AR'] = float(soup.find(id="cotizacionArg")['value'])
currencies['UY'] = float(soup.find(id="cotizacionUy")['value'])
currencies['date'] = now.strftime("%H:%M %d/%m/%Y")

async def sendGame(message, gameid, iscommand):
game = json.loads(requests.get(f'https://store.steampowered.com/api/appdetails/?appids={gameid}&cc=AR&l=english&v=1').text)

if message.content.startswith("!sp "):
if not game[gameid]['success']:
if iscommand: await message.channel.send(f'Juego con ID **{gameid}** no encontrado')
return
if game[gameid]['data']['is_free']:
if iscommand: await message.channel.send(f"El juego **{game[gameid]['data']['name']}** ya es gratis")
return
if not "price_overview" in game[gameid]['data']:
if iscommand: await message.channel.send(f"Flaco esto no tiene precio")
return

priceUyString = json.loads(requests.get(f'https://store.steampowered.com/api/appdetails/?appids={gameid}&cc=UY&l=english&v=1').text)[gameid]['data']['price_overview']['final_formatted'].split('U')[1]
priceArgString = game[gameid]['data']['price_overview']['final_formatted'].split(' ')[1]
priceArg = float(priceArgString.replace(".", "").replace(",", ".")) * taxArg
priceUy = float(priceUyString.replace(".", "").replace(",", "."))

priceArgConv = (priceArg * currencies['UY']) / currencies['AR']

#TODO
#Reformat this shitty message now that the code is public
await message.channel.send(f"**{game[gameid]['data']['name']}**\n\nPrecio en Uruguay: **{priceUy}** :flag_uy: \nPrecio en Argentina: **{round(priceArgConv, 2)}** :flag_uy: ({round(priceArg, 2)} :flag_ar: )\n\nAhorro: {round(priceUy - priceArgConv, 2)} :flag_uy: - {round(100 - ((priceArgConv * 100) / priceUy), 1)}%\n\n1 :flag_uy: = {round(currencies['AR'] / currencies['UY'], 2)} :flag_ar: (Prex {currencies['date']})\nAbrir con steam: <steam://store/{gameid}>")

@bot.event
async def on_message(message):
if message.content.split(' ')[0].startswith("https://store.steampowered.com/app/"):
gameid = message.content.split(' ')[0].split('/')[4]
await sendGame(message, gameid, False)

if message.content.startswith("!sp "):
s = message.content[4:]
gameid = getGameWithName(s)

if gameid: await sendGame(message, gameid, True)
else: await message.channel.send(f'No hay resultados para "{s}"')






bot.run(config.BOTTOKEN, reconnect=True)

0 comments on commit 687742b

Please sign in to comment.