Skip to content

Commit

Permalink
Even more improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
silasary committed Feb 14, 2020
1 parent 4c67742 commit 324925f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
6 changes: 3 additions & 3 deletions decksite/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from decksite.data import competition, deck, match, person, query
from decksite.data.form import Form
from decksite.database import db
from magic import card, decklist, fetcher, legality, rotation
from magic import card, decklist, legality, rotation
from magic.decklist import DecklistType
from magic.models import Deck
from shared import configuration, dtutil, guarantee, redis
from shared import configuration, dtutil, fetch_tools, guarantee, redis
from shared.container import Container
from shared.database import sqlescape
from shared.pd_exception import InvalidDataException, LockNotAcquiredException
Expand Down Expand Up @@ -275,7 +275,7 @@ def report(form: ReportForm) -> bool:
match.insert_match(dtutil.now(), form.entry, form.entry_games, form.opponent, form.opponent_games, None, None, mtgo_match_id)
if not pdbot:
if configuration.get('league_webhook_id') and configuration.get('league_webhook_token'):
fetcher.post_discord_webhook(
fetch_tools.post_discord_webhook(
configuration.get_str('league_webhook_id'),
configuration.get_str('league_webhook_token'),
'{entry} reported {f.entry_games}-{f.opponent_games} vs {opponent}'.format(f=form, entry=entry_deck.person, opponent=opponent_deck.person)
Expand Down
2 changes: 1 addition & 1 deletion maintenance/post_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def ad_hoc() -> None:
reprime_cache.run() # Update deck legalities
insert_seasons.run() # Make sure Season table is up to date
if redis.REDIS: # Clear the redis cache
redis.REDIS.flushdb() # type: ignore[no-untyped-call]
redis.REDIS.flushdb()
league_end = league.active_league().end_date
diff = league_end - dtutil.now()
if diff.days > 0:
Expand Down
21 changes: 1 addition & 20 deletions modo_bugs/fetcher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
from typing import Any, Dict, List, Tuple
from typing import Dict, List, Tuple

from bs4 import BeautifulSoup
from bs4.element import Tag
Expand Down Expand Up @@ -94,22 +94,3 @@ def get_article_archive() -> List[Tuple[Tag, str]]:
html = fetch_tools.fetch('http://magic.wizards.com/en/articles/archive/')
soup = BeautifulSoup(html, 'html.parser')
return [parse_article_item_extended(a) for a in soup.find_all('div', class_='article-item-extended')]

#pylint: disable=R0913
def post_discord_webhook(webhook_id: str,
webhook_token: str,
message: str = None,
username: str = None,
avatar_url: str = None,
embeds: List[Dict[str, Any]] = None
) -> bool:
if webhook_id is None or webhook_token is None:
return False
url = 'https://discordapp.com/api/webhooks/{id}/{token}'.format(id=webhook_id, token=webhook_token)
fetch_tools.post(url, json_data={
'content': message,
'username': username,
'avatar_url': avatar_url,
'embeds': embeds,
})
return True
2 changes: 1 addition & 1 deletion modo_bugs/scrape_announcements.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def parse_build_notes(h: Tag) -> None:
'url': fetcher.find_announcements()[0],
}
if configuration.get_optional_str('bugs_webhook_id') is not None:
fetcher.post_discord_webhook(
fetch_tools.post_discord_webhook(
configuration.get_str('bugs_webhook_id'),
configuration.get_str('bugs_webhook_token'),
embeds=[embed],
Expand Down
28 changes: 26 additions & 2 deletions rotation_script/rotation_script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import fileinput
import os
import pathlib
import shutil
import subprocess
from collections import Counter
Expand All @@ -10,7 +11,7 @@

from magic import fetcher, rotation
from price_grabber.parser import PriceListType, parse_cardhoarder_prices, parse_mtgotraders_prices
from shared import configuration, dtutil, fetch_tools, text
from shared import configuration, dtutil, fetch_tools, repo, text

BLACKLIST: Set[str] = set()
WHITELIST: Set[str] = set()
Expand Down Expand Up @@ -152,8 +153,31 @@ def do_push() -> None:
os.chdir(gh_repo)
subprocess.run(['git', 'add'] + files, check=True)
subprocess.run(['git', 'commit', '-m', f'{setcode} {rottype}'], check=True)
subprocess.run(['git', 'push'] + files, check=True)
subprocess.run(['git', 'push'], check=True)
checklist = f"""{setcode} {rottype} checklist
https://pennydreadfulmagic.com/admin/rotation/
- [ ] upload legal_cards.txt to S3
- [ ] upload {setcode}_legal_cards.txt to S3
- [ ] restart discordbot
- [ ] ping scryfall
- [ ] email mtggoldfish
- [ ] ping tappedout
"""
ds = os.path.expanduser('~/decksite/')
if os.path.exists(ds):
os.chdir(ds)
subprocess.run(['python3', 'maintenance', 'post_rotation'], check=True)
else:
checklist += '- [ ] run post_rotation\n'
try:
fetch_tools.post('https://gatherling.com/util/updateDefaultFormats.php')
except fetch_tools.FetchException:
checklist += '- [ ] Update Gatherling legal cards list'
srv = pathlib.Path('/etc/uwsgi/vassals/decksite.ini')
if srv.exists():
srv.touch()
else:
checklist += '- [ ] touch /etc/uwsgi/vassals/decksite.ini\n'
repo.create_issue(checklist, 'rotation script', 'rotation')
22 changes: 21 additions & 1 deletion shared/fetch_tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import urllib.request
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional

import aiohttp
import requests
Expand Down Expand Up @@ -129,3 +129,23 @@ def escape(str_input: str, skip_double_slash: bool = False) -> str:
if skip_double_slash:
s = s.replace('-split-', '//')
return s

#pylint: disable=R0913
def post_discord_webhook(webhook_id: str,
webhook_token: str,
message: str = None,
username: str = None,
avatar_url: str = None,
embeds: List[Dict[str, Any]] = None
) -> bool:
if webhook_id is None or webhook_token is None:
return False
url = 'https://discordapp.com/api/webhooks/{id}/{token}'.format(
id=webhook_id, token=webhook_token)
post(url, json_data={
'content': message,
'username': username,
'avatar_url': avatar_url,
'embeds': embeds,
})
return True

0 comments on commit 324925f

Please sign in to comment.