mirror of https://github.com/ekimekim/wubloader
api_ping: A simple util for hitting google apis to prevent inactivity
parent
2dbd1132fe
commit
3489b0abaf
@ -0,0 +1,17 @@
|
||||
FROM alpine:3.7
|
||||
# dependencies needed for compiling c extensions
|
||||
# also busybox-extras for telnet for easier use of backdoor
|
||||
RUN apk --update add py2-pip gcc python-dev musl-dev busybox-extras
|
||||
|
||||
# Install gevent so that we don't need to re-install it when common changes
|
||||
RUN pip install gevent
|
||||
|
||||
# Install common lib first as it changes less
|
||||
COPY common /tmp/common
|
||||
RUN pip install /tmp/common && rm -r /tmp/common
|
||||
|
||||
# Install actual application
|
||||
COPY api_ping /tmp/api_ping
|
||||
RUN pip install /tmp/api_ping && rm -r /tmp/api_ping
|
||||
|
||||
ENTRYPOINT ["python2", "-m", "api_ping"]
|
@ -0,0 +1,16 @@
|
||||
|
||||
import gevent.monkey
|
||||
gevent.monkey.patch_all()
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
import argh
|
||||
|
||||
from api_ping.main import main
|
||||
|
||||
LOG_FORMAT = "[%(asctime)s] %(levelname)8s %(name)s(%(module)s:%(lineno)d): %(message)s"
|
||||
|
||||
level = os.environ.get('WUBLOADER_LOG_LEVEL', 'INFO').upper()
|
||||
logging.basicConfig(level=level, format=LOG_FORMAT)
|
||||
argh.dispatch_command(main)
|
@ -0,0 +1,49 @@
|
||||
|
||||
import json
|
||||
|
||||
from common.googleapis import GoogleAPIClient
|
||||
|
||||
# Youtube video to look up (look at this graph)
|
||||
YOUTUBE_VIDEO_ID = 'sIlNIVXpIns'
|
||||
|
||||
# Sheet id to look up (DB2019 public sheet)
|
||||
SHEET_ID = '15t-UsfNlP5xUxLTLH-EUjrOYriOvXuNGAPxi_8EZJhU'
|
||||
|
||||
|
||||
def youtube(client):
|
||||
client.request('GET', 'https://www.googleapis.com/youtube/v3/videos',
|
||||
params={'part': 'id', 'id': YOUTUBE_VIDEO_ID},
|
||||
).raise_for_status()
|
||||
|
||||
|
||||
def sheets(client):
|
||||
client.request('GET',
|
||||
'https://sheets.googleapis.com/v4/spreadsheets/{}/values/A1'.format(SHEET_ID),
|
||||
).raise_for_status()
|
||||
|
||||
|
||||
ACTIONS = {
|
||||
'youtube': youtube,
|
||||
'sheets': sheets,
|
||||
}
|
||||
|
||||
|
||||
def main(
|
||||
*targets
|
||||
):
|
||||
"""Does an action on the given google api targets, preventing issues due to api inactivity.
|
||||
A target should consist of a comma-seperated list of apis to hit, then a colon, then a creds file.
|
||||
eg. "sheets,youtube:my_creds.json".
|
||||
"""
|
||||
for target in targets:
|
||||
if ':' not in target:
|
||||
raise ValueError("Bad target: {!r}".format(target))
|
||||
apis, credfile = target.split(':', 1)
|
||||
apis = apis.split(',')
|
||||
with open(credfile) as f:
|
||||
creds = json.load(f)
|
||||
client = GoogleAPIClient(creds['client_id'], creds['client_secret'], creds['refresh_token'])
|
||||
for api in apis:
|
||||
if api not in ACTIONS:
|
||||
raise ValueError("No such api {!r}".format(api))
|
||||
ACTIONS[api](client)
|
@ -0,0 +1,12 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name = "wubloader-api-ping",
|
||||
version = "0.0.0",
|
||||
packages = find_packages(),
|
||||
install_requires = [
|
||||
"argh",
|
||||
"requests",
|
||||
"wubloader-common",
|
||||
],
|
||||
)
|
Loading…
Reference in New Issue