Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #29

Merged
merged 2 commits into from
Nov 16, 2023
Merged

Dev #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/api/factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

Expand Down
2 changes: 0 additions & 2 deletions app/celery_broker/factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from celery import Celery

from app.config import settings
Expand Down
2 changes: 0 additions & 2 deletions app/celery_broker/metadata_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import json
import os
import pathlib

import app.repositories as repositories
from app.models.enums import MetadataType, ProcessStatus
Expand Down
1 change: 0 additions & 1 deletion app/crawler/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/spider-middleware.html
import os
from pathlib import Path

from app.config import settings
Expand Down
1 change: 0 additions & 1 deletion app/models/website.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from datetime import datetime, timedelta
from typing import Optional, Any

Expand Down
23 changes: 13 additions & 10 deletions app/mongo.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import os

from app.config import settings
from pymongo import MongoClient


client = MongoClient(host=settings.MONGO_URI)
db = client[settings.MONGO_DBNAME]
db = None


db[settings.MONGO_WEBSITES_COLLECTION].create_index(
[("id", 1)], unique=True
)
db[settings.MONGO_WEBSITES_COLLECTION].create_index(
[("url", 1)], unique=True
)
db[settings.MONGO_CRAWLS_COLLECTION].create_index([("id", 1)], unique=True)
def init_database():
global db
if db is None:
db = client[settings.MONGO_DBNAME]
db[settings.MONGO_WEBSITES_COLLECTION].create_index(
[("id", 1)], unique=True
)
db[settings.MONGO_WEBSITES_COLLECTION].create_index(
[("url", 1)], unique=True
)
db[settings.MONGO_CRAWLS_COLLECTION].create_index([("id", 1)], unique=True)
5 changes: 0 additions & 5 deletions app/repositories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from .crawls import crawls
from .websites import websites
from .files import files

__all__ = ["crawls", "websites", "files"]
4 changes: 2 additions & 2 deletions app/repositories/crawls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os
from pymongo.results import InsertOneResult

from app.celery_broker.utils import french_datetime
from app.config import settings
from app.models.crawl import CrawlModel, ListCrawlResponse
from app.models.enums import ProcessStatus
from app.models.metadata import MetadataTask
from app.mongo import db
from app.mongo import db, init_database


class CrawlsRepository:
"""Operations for crawls collection"""

def __init__(self):
init_database()
self.collection = db[settings.MONGO_CRAWLS_COLLECTION]

def create(self, data: CrawlModel) -> str:
Expand Down
4 changes: 2 additions & 2 deletions app/repositories/websites.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from typing import Any

from pymongo.results import InsertOneResult, UpdateResult
Expand All @@ -8,13 +7,14 @@
from app.models.enums import ProcessStatus
from app.models.request import UpdateWebsiteRequest
from app.models.website import WebsiteModel, ListWebsiteResponse
from app.mongo import db
from app.mongo import db, init_database


class WebsitesRepository:
"""Operations for websites collection"""

def __init__(self):
init_database()
self.collection = db[settings.MONGO_WEBSITES_COLLECTION]

def list(
Expand Down
1 change: 0 additions & 1 deletion app/s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from functools import wraps
from minio import Minio

Expand Down
1 change: 0 additions & 1 deletion app/services/responsiveness_calculator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from typing import Any

import requests
Expand Down
1 change: 0 additions & 1 deletion tests/tests_services/test_responsiveness_calculator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import unittest
from unittest.mock import patch, Mock

Expand Down
Loading