forked from Zaunei/flathunter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from codders/feat/web-interface
Added web interface for Flathunter
- Loading branch information
Showing
37 changed files
with
978 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This file specifies files that are *not* uploaded to Google Cloud Platform | ||
# using gcloud. It follows the same syntax as .gitignore, with the addition of | ||
# "#!include" directives (which insert the entries of the given .gitignore-style | ||
# file at that point). | ||
# | ||
# For more information, run: | ||
# $ gcloud topic gcloudignore | ||
# | ||
.gcloudignore | ||
# If you would like to upload your .git directory, .gitignore file or files | ||
# from your .gitignore file, remove the corresponding line | ||
# below: | ||
.git | ||
.gitignore | ||
|
||
# Python pycache: | ||
__pycache__/ | ||
# Ignored by the build system | ||
/setup.cfg | ||
/Pipfile | ||
/Pipfile.lock | ||
|
||
# Don't upload the database | ||
processed_ids.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
language: python | ||
python: | ||
- "3.5" | ||
- "3.6" | ||
- "3.7" | ||
- "3.8" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
runtime: python37 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cron: | ||
- description: "Hunt for flats" | ||
url: /hunt | ||
schedule: every 30 minutes synchronized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
import yaml | ||
import logging | ||
|
||
class Config: | ||
|
||
__log__ = logging.getLogger(__name__) | ||
|
||
def __init__(self, filename=None, string=None): | ||
if string is not None: | ||
self.config = yaml.safe_load(string) | ||
return | ||
if filename is None: | ||
filename = os.path.dirname(os.path.abspath(__file__)) + "/../config.yaml" | ||
self.__log__.info("Using config %s" % filename) | ||
with open(filename) as file: | ||
self.config = yaml.safe_load(file) | ||
|
||
def __iter__(self): | ||
return self.config.__iter__() | ||
|
||
def __getitem__(self, value): | ||
return self.config[value] | ||
|
||
def get(self, key, value=None): | ||
return self.config.get(key, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import logging | ||
import firebase_admin | ||
import traceback | ||
import datetime | ||
from firebase_admin import credentials | ||
from firebase_admin import firestore | ||
|
||
from flathunter.config import Config | ||
|
||
class ConnectionWrapper: | ||
|
||
def __init__(self, db): | ||
self.db = db | ||
|
||
def __enter__(self): | ||
# Return a new client for this thread | ||
return firestore.client() | ||
|
||
def __exit__(self, exc_type, exc_value, tb): | ||
if exc_type is not None: | ||
traceback.print_exception(exc_type, exc_value, tb) | ||
return False | ||
return True | ||
|
||
class GoogleCloudIdMaintainer: | ||
__log__ = logging.getLogger(__name__) | ||
|
||
def __init__(self): | ||
project_id = Config().get('google_cloud_project_id') | ||
if project_id is None: | ||
raise Exception("Need to project a google_cloud_project_id in config.yaml") | ||
firebase_admin.initialize_app(credentials.ApplicationDefault(), { | ||
'projectId': project_id | ||
}) | ||
self.db = firestore.client() | ||
|
||
def connect(self): | ||
return ConnectionWrapper(self.db) | ||
|
||
def add(self, expose_id, connection=None): | ||
self.__log__.debug('add(' + str(expose_id) + ')') | ||
self.db.collection(u'exposes').document(str(expose_id)).set({ u'id': expose_id }) | ||
|
||
def get(self, connection=None): | ||
res = [] | ||
for doc in self.db.collection(u'exposes').stream(): | ||
res.append(doc.to_dict()[u'id']) | ||
|
||
self.__log__.info('already processed: ' + str(len(res))) | ||
self.__log__.debug(str(res)) | ||
return res | ||
|
||
def get_last_run_time(self, connection=None): | ||
for doc in self.db.collection(u'executions').order_by(u'timestamp', direction=firestore.Query.DESCENDING).limit(1).stream(): | ||
return doc.to_dict()[u'timestamp'] | ||
|
||
def update_last_run_time(self, connection=None): | ||
time = datetime.datetime.now() | ||
self.db.collection(u'executions').add({ u'timestamp': time }) | ||
return time |
Oops, something went wrong.