Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Rewrite apartment_firestore repo and remove test
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsabri committed Oct 24, 2023
1 parent 575b7cc commit 0741e8b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 65 deletions.
14 changes: 8 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from src.usecase.apartment import ApartmentUseCase
from src.infrastructure.discord import DiscordInfrastructure
from src.repositories.scraper import ScraperRepository
from firebase_admin import credentials
from firebase_admin import firestore, initialize_app, credentials

import os
import json

def main():
scraper_repository = ScraperRepository()
apartment_repository = ApartmentFirestoreRepository(FIRESTORE_CRED)
apartment_repository = ApartmentFirestoreRepository(db)
discord_infra = DiscordInfrastructure(INPUT_DISCORD_WEBHOOK_URL)
apartment_usecase = ApartmentUseCase(scraper_repository, apartment_repository, discord_infra)

Expand All @@ -20,18 +20,20 @@ def main():

if __name__ == "__main__":
INPUT_DISCORD_WEBHOOK_URL = os.environ["DISCORD_WEBHOOK_URL"]
FIRESTORE_CRED = credentials.Certificate(json.loads(os.environ["FIREBASE_ACCOUNT"]))
INPUT_APARTMENTS_URL = (
os.environ.get("APARTMENTS_URL")
or "https://bostad.stockholm.se/bostad/?sort=annonserad-fran-desc&ungdom=1"
#or "https://bostad.stockholm.se/bostad/?sort=annonserad-fran-desc&ungdom=1&s=59.33489&n=59.34250&w=18.04110&e=18.05474&hide-filter=true"
#or "https://bostad.stockholm.se/bostad/?sort=annonserad-fran-desc&ungdom=1"
or "https://bostad.stockholm.se/bostad/?sort=annonserad-fran-desc&ungdom=1&s=59.33489&n=59.34250&w=18.04110&e=18.05474&hide-filter=true"
)
INPUT_APARTMENTS_FILTER = os.environ.get("APARTMENTS_FILTER") # Defaults to None if env not set

if INPUT_APARTMENTS_FILTER:
try:
INPUT_APARTMENTS_FILTER = json.loads(INPUT_APARTMENTS_FILTER)
except (TypeError, json.JSONDecodeError):
raise ValueError("APARTMENTS_FILTER must be a valid JSON object")

FIRESTORE_CRED = credentials.Certificate(json.loads(os.environ["FIREBASE_ACCOUNT"]))
initialize_app(FIRESTORE_CRED)
db = firestore.client()

main()
8 changes: 2 additions & 6 deletions src/repositories/apartment_firestore.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import os
import firebase_admin

from firebase_admin import firestore
from google.api_core import exceptions

from src.entities.apartment import Apartment

class ApartmentFirestoreRepository:
def __init__(self, credentials):
firebase_admin.initialize_app(credentials)

self.db = firestore.client()
def __init__(self, db):
self.db = db
self.collection_name = "apartment_listings"

def post_apartment_listing(self, apartment: Apartment):
Expand Down
53 changes: 0 additions & 53 deletions tests/repositories/test_apartment_firestore.py

This file was deleted.

0 comments on commit 0741e8b

Please sign in to comment.