Skip to content

Commit 9b05207

Browse files
authored
dailypop: Add support for Daily Pop as an outlet (#198)
* add downloader for daily pop puzzles * readme: add daily pop support * workflow: add daily pop to tests
1 parent cc5aabc commit 9b05207

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

.github/workflows/status-check-outlets.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
- name: Test Daily Beast latest
4141
if: '!cancelled()'
4242
run: xword-dl db
43+
- name: Test Daily Pop latest
44+
if: '!cancelled()'
45+
run: xword-dl pop
4346
- name: Test Der Standard latest
4447
if: '!cancelled()'
4548
run: xword-dl std

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Supported outlets:
99
|*Atlantic*|`atl`|✔️|✔️||
1010
|*Crossword Club*|`club`|✔️|✔️|✔️|
1111
|*The Daily Beast*|`db`|✔️|||
12+
|*Daily Pop*|`pop`|✔️|✔️||
1213
|*Der Standard*|`std`|✔️||✔️|
1314
|*The Globe And Mail cryptic*|`tgam`|✔️|✔️|✔️|
1415
|*Guardian Cryptic*|`grdc`|✔️||✔️|
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import datetime
2+
import requests
3+
import urllib
4+
5+
from .compilerdownloader import CrosswordCompilerDownloader
6+
from ..util import XWordDLException
7+
8+
class DailyPopDownloader(CrosswordCompilerDownloader):
9+
outlet = 'Daily Pop'
10+
command = 'pop'
11+
outlet_prefix = 'Daily Pop'
12+
13+
def __init__(self, **kwargs):
14+
super().__init__(**kwargs)
15+
16+
self.api_url = 'https://api.puzzlenation.com/dailyPopCrosswords/puzzles/daily/'
17+
18+
self.settings['headers'] = self.settings.get('headers', {})
19+
if 'x-api-key' not in self.settings['headers']:
20+
self.settings['headers']['x-api-key'] = self.get_api_key()
21+
22+
def get_api_key(self):
23+
res = requests.get('http://dailypopcrosswordsweb.puzzlenation.com/crosswordSetup.js')
24+
25+
api_key = None
26+
27+
for l in res.text.splitlines():
28+
if l.startswith('const API_KEY = '):
29+
api_key = l[len('const API_KEY = "'):-2]
30+
31+
if not api_key:
32+
raise XWordDLException('Could not find Daily Pop API Key.')
33+
34+
return api_key
35+
36+
def find_by_date(self, dt):
37+
url_formatted_date = dt.strftime('%y%m%d')
38+
self.date = dt
39+
return urllib.parse.urljoin(self.api_url, url_formatted_date)
40+
41+
def find_latest(self):
42+
dt = datetime.datetime.today()
43+
return self.find_by_date(dt)
44+
45+
def fetch_data(self, url):
46+
res = requests.get(url, headers=self.settings['headers'])
47+
48+
return res.text

0 commit comments

Comments
 (0)