Skip to content

Commit c395533

Browse files
authored
fetch PR info from rest api (#43)
1 parent 5ddb40c commit c395533

18 files changed

+344
-224
lines changed

app/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
import sentry_sdk
1212
from sentry_sdk.integrations.flask import FlaskIntegration
1313

14-
app = Flask(__name__.split('.')[0])
15-
app.config.from_object('config')
14+
app = Flask(__name__.split(".")[0])
15+
app.config.from_object("config")
1616

1717
# Error tracking infrastructure
18-
if not os.environ.get('DEBUG', ''):
19-
sentry_sdk.init(dsn="https://[email protected]/1384470",
20-
integrations=[FlaskIntegration()])
18+
if not os.environ.get("DEBUG", ""):
19+
sentry_sdk.init(
20+
dsn="https://[email protected]/1384470",
21+
integrations=[FlaskIntegration()],
22+
)
2123
else:
22-
print('WARNING: SENTRY NOT INITIALIZED', file=sys.stderr)
24+
print("WARNING: SENTRY NOT INITIALIZED", file=sys.stderr)
2325

24-
app.config['CURRENT_YEAR'] = datetime.datetime.now().year
26+
app.config["CURRENT_YEAR"] = datetime.datetime.now().year
2527

2628
from app import view
2729

app/model/adopters.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .. import app
1010

1111

12-
_ADOPTERS_DIRECTORY_PATH = os.path.join(app.root_path, '..', 'adopters')
12+
_ADOPTERS_DIRECTORY_PATH = os.path.join(app.root_path, "..", "adopters")
1313

1414

1515
class Adopter:
@@ -18,16 +18,16 @@ def __init__(self, name: str, logo_file_name: str, website: str):
1818
self.logo_file_name = str(logo_file_name)
1919

2020
website = str(website)
21-
if '://' in website:
21+
if "://" in website:
2222
self.website_url = website
2323
else:
24-
self.website_url = 'http://' + website
24+
self.website_url = "http://" + website
2525

2626

2727
def get_list() -> typing.Iterable[Adopter]:
28-
entries = list(sorted(map(os.path.basename, glob.glob(_ADOPTERS_DIRECTORY_PATH + '/*.png'))))
28+
entries = list(sorted(map(os.path.basename, glob.glob(_ADOPTERS_DIRECTORY_PATH + "/*.png"))))
2929
for e in entries:
30-
name, website = e.rsplit('.', 1)[0].rsplit(' ', 1)
30+
name, website = e.rsplit(".", 1)[0].rsplit(" ", 1)
3131
yield Adopter(name, e, website)
3232

3333

app/model/cache.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,41 @@
1010
from .. import app
1111

1212

13-
def get(url,
14-
background_update_interval,
15-
cache_expiration_timeout,
16-
headers=None):
13+
def get(url, background_update_interval, cache_expiration_timeout, headers=None):
1714
"""
1815
Returns None if such URL is not (yet) cached.
1916
Cached entries will be removed after the specified period of inactivity.
2017
The timing parameters should not change between calls;
2118
otherwise, their actual values may vary unpredictably within the supplied ranges.
2219
"""
2320
if background_update_interval >= cache_expiration_timeout:
24-
raise ValueError('The background update interval must be lower than the data expiration timeout')
21+
raise ValueError("The background update interval must be lower than the data expiration timeout")
2522

2623
# First, decide if it is time to launch a background update yet.
2724
# Due to the race condition, we may accidentally start multiple updates concurrently, but this is fine.
28-
lock_key = 'lock-' + url
25+
lock_key = "lock-" + url
2926
if not expiring_storage.read(lock_key):
3027
expiring_storage.write(lock_key, True, timeout=float(background_update_interval))
31-
threading.Thread(target=lambda: _do_background_update(url, headers, cache_expiration_timeout),
32-
daemon=False).start()
28+
threading.Thread(
29+
target=lambda: _do_background_update(url, headers, cache_expiration_timeout),
30+
daemon=False,
31+
).start()
3332

3433
return expiring_storage.read(url)
3534

3635

3736
def _do_background_update(url, headers, cache_expiration_timeout):
38-
app.logger.info('Initiating background update from %r with headers %r', url, headers)
37+
app.logger.info("Initiating background update from %r with headers %r", url, headers)
3938

4039
started_at = time.monotonic()
4140
r = urllib.request.Request(url, headers=headers or {})
4241
data = urllib.request.urlopen(r).read()
4342

4443
expiring_storage.write(url, data, timeout=float(cache_expiration_timeout))
4544

46-
app.logger.info('Background update OK: saved %.1f KiB from %r in %.3f seconds',
47-
len(data) / 1024,
48-
url,
49-
time.monotonic() - started_at)
45+
app.logger.info(
46+
"Background update OK: saved %.1f KiB from %r in %.3f seconds",
47+
len(data) / 1024,
48+
url,
49+
time.monotonic() - started_at,
50+
)

0 commit comments

Comments
 (0)