From 9bc9c2d3998fd2f81e939c67463c25ba24ca7b3c Mon Sep 17 00:00:00 2001 From: mskarlin <12701035+mskarlin@users.noreply.github.com> Date: Sat, 11 Nov 2023 12:00:39 -0500 Subject: [PATCH] Search features (#8) * Add search endpoint Add conditional room deletion (if only 1 the you can't) Remove auto-adding art if 1 work in 1 room Add overwrite room ability to store Add search API * Add make commands for deploy Add warmpup endpoints * Add material ui for browser notif remove former splash page Move search to top bar * Update sitemap and index * spacing * Add blog endpoints Add blog datastore entrypoint Add blog links Add blog components Add covid scraper Add blog notebook * Update sitemap with blog links * Fix bug with blank tag raising exception * helmet and blog updates for main page remove console logs for blog --- Makefile | 6 + art_snob_api/main.py | 33 +- art_snob_api/src/datastore_helpers.py | 1 + art_snob_api/utilities/datastore_helpers.py | 3 +- art_snob_frontend/package.json | 2 + art_snob_frontend/public/index.html | 2 +- art_snob_frontend/public/sitemap.txt | 72 +- art_snob_frontend/src/App.css | 13 +- art_snob_frontend/src/App.js | 175 +- art_snob_frontend/src/artBrowse.js | 100 +- art_snob_frontend/src/artComponents.js | 7 +- art_snob_frontend/src/blog.js | 272 +++ art_snob_frontend/src/detailView.js | 8 +- art_snob_frontend/src/firebase.js | 6 +- art_snob_frontend/src/purchasePage.js | 7 +- art_snob_frontend/src/store.js | 34 +- art_snob_frontend/src/tasteFinder.js | 13 +- art_snob_frontend/yarn.lock | 17 + covid_scraper/.gcloudignore | 19 + covid_scraper/app.yaml | 26 + covid_scraper/cron.yaml | 5 + covid_scraper/main.py | 84 + covid_scraper/requirements.txt | 76 + covid_scraper/scrape.py | 1 + covid_scraper/utilities/__init__.py | 0 covid_scraper/utilities/credentials.py | 18 + covid_scraper/utilities/custom_logging.py | 134 ++ covid_scraper/utilities/datastore_helpers.py | 337 ++++ covid_scraper/utilities/storage_helpers.py | 29 + image_model_api/.gcloudignore | 19 + image_model_api/app.yaml | 29 + image_model_api/main.py | 70 + image_model_api/requirements.txt | 19 + notebooks/Upload Blog Article.ipynb | 186 ++ notebooks/bs4_covid_scrape.ipynb | 190 ++ notebooks/dev_view_art_to_label.ipynb | 1779 +++++++++++++++++- utilities/storage_helpers.py | 13 + 37 files changed, 3668 insertions(+), 137 deletions(-) create mode 100644 art_snob_frontend/src/blog.js create mode 100644 covid_scraper/.gcloudignore create mode 100644 covid_scraper/app.yaml create mode 100644 covid_scraper/cron.yaml create mode 100644 covid_scraper/main.py create mode 100644 covid_scraper/requirements.txt create mode 100644 covid_scraper/scrape.py create mode 100644 covid_scraper/utilities/__init__.py create mode 100644 covid_scraper/utilities/credentials.py create mode 100644 covid_scraper/utilities/custom_logging.py create mode 100644 covid_scraper/utilities/datastore_helpers.py create mode 100644 covid_scraper/utilities/storage_helpers.py create mode 100644 image_model_api/.gcloudignore create mode 100644 image_model_api/app.yaml create mode 100644 image_model_api/main.py create mode 100644 image_model_api/requirements.txt create mode 100644 notebooks/Upload Blog Article.ipynb create mode 100644 notebooks/bs4_covid_scrape.ipynb diff --git a/Makefile b/Makefile index 04e4902..e5d6285 100644 --- a/Makefile +++ b/Makefile @@ -78,3 +78,9 @@ deploy-frontend: cd art_snob_frontend ; npm run build cp -r art_snob_frontend/build ./build_deploy/build/ cd build_deploy ; gcloud app deploy + +deploy-backend: + cd art_snob_api ; gcloud app deploy + +deploy-image-api: + cd image_model_api ; gcloud beta app deploy --no-cache \ No newline at end of file diff --git a/art_snob_api/main.py b/art_snob_api/main.py index 13e023e..993161c 100644 --- a/art_snob_api/main.py +++ b/art_snob_api/main.py @@ -46,7 +46,7 @@ data = FriendlyDataStore(dsi) eec = ClusterExplore(data) -app = FastAPI(title='deco-api', version="0.5.0") +app = FastAPI(title='artsnob-api', version="0.6.0") origins = ["*", "http://localhost:8000/"] @@ -559,5 +559,36 @@ def share(app_state: AppState, except Exception as e: print(e.message) +@app.get("/_ah/warmup") +def warmup(): + return {'status': 'warming-up'} + +@app.get('/blog/{blog_name}') +def blog(blog_name: str, session_id=None): + + if not session_id: + session_id = str(uuid.uuid4()) + + blog_name = blog_name.lower().replace('%2c', ',').replace('\'', '').replace(' ','_') + article = dsi.read_nocache(ids=[blog_name], kind=data.BLOG, sorted_list=True) + + if article: + return {'blog': article[0]} + else: + return {'blog': None} + +@app.get('/list_blogs/') +def list_blogs(session_id=None): + + if not session_id: + session_id = str(uuid.uuid4()) + + articles = dsi.query(kind = data.BLOG, n_records = 100, tolist = True) + + # extract and sort by pub date + articles = [articles[0] for ak in articles] + + return {'articles': articles[0]} + if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8080) \ No newline at end of file diff --git a/art_snob_api/src/datastore_helpers.py b/art_snob_api/src/datastore_helpers.py index 9daefc2..fd52ca0 100644 --- a/art_snob_api/src/datastore_helpers.py +++ b/art_snob_api/src/datastore_helpers.py @@ -51,6 +51,7 @@ class FriendlyDataStore(): STATE_KIND = '12202020-state' STATE_LOGIN = '12202020-login' SEARCH_API_URL = os.environ.get('SEARCH_API_URL', 'http://localhost:8001') + BLOG='artsnob-blog-articles' # RAND_MIN = 4503653962481664 # used for scraped-image-data indices # RAND_MAX = 6755350696951808 RAND_MIN = 1 diff --git a/art_snob_api/utilities/datastore_helpers.py b/art_snob_api/utilities/datastore_helpers.py index 47476c4..2eadf74 100644 --- a/art_snob_api/utilities/datastore_helpers.py +++ b/art_snob_api/utilities/datastore_helpers.py @@ -225,8 +225,7 @@ def read_nocache(self, ids: List[Union[int, str]], kind: str, filter_keys: List[ (dict) keyed to record id or sorted list by input ids """ - - keys = [self.ds.key(kind, idx) for idx in ids] + keys = [self.ds.key(kind, idx) for idx in ids if idx != ''] results = self.ds.get_multi(keys) if results: diff --git a/art_snob_frontend/package.json b/art_snob_frontend/package.json index 8bb70f6..cff2edb 100644 --- a/art_snob_frontend/package.json +++ b/art_snob_frontend/package.json @@ -20,11 +20,13 @@ "html2canvas": "^1.0.0-rc.7", "lodash": "^4.17.20", "material-design-icons": "^3.0.1", + "material-ui-cookie-consent": "^0.1.0", "mathjs": "^7.1.0", "node-sass": "^4.14.1", "react": "^16.13.1", "react-cookie": "^4.0.3", "react-dom": "^16.13.1", + "react-ga": "^3.3.0", "react-helmet": "^6.1.0", "react-hook-form": "^6.8.4", "react-pro-sidebar": "^0.4.3", diff --git a/art_snob_frontend/public/index.html b/art_snob_frontend/public/index.html index c24df62..92670f1 100644 --- a/art_snob_frontend/public/index.html +++ b/art_snob_frontend/public/index.html @@ -6,7 +6,7 @@ + content="Quickly find and build an affordable wall art that matches your taste with our art finder app." />