-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10b15da
commit cec3f5f
Showing
12 changed files
with
141 additions
and
13 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
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 |
---|---|---|
|
@@ -2,4 +2,3 @@ psycopg2-binary | |
atproto | ||
peewee | ||
python-dotenv | ||
apscheduler |
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,18 @@ | ||
FROM python:3.11-slim | ||
|
||
WORKDIR /app | ||
|
||
# Install system dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
gcc \ | ||
libpq-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy requirements first to leverage Docker cache | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Copy application code | ||
COPY . . | ||
|
||
CMD ["python", "db_scheduler.py"] |
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,33 @@ | ||
from datetime import datetime, timedelta, timezone | ||
from utils.config import POSTGRES_DB, POSTGRES_PASSWORD, POSTGRES_USER | ||
import peewee | ||
|
||
# Database setup | ||
db = peewee.PostgresqlDatabase(POSTGRES_DB, user=POSTGRES_USER, password=POSTGRES_PASSWORD, host='postgres', port=5432) | ||
|
||
# Database Models | ||
class BaseModel(peewee.Model): | ||
class Meta: | ||
database = db | ||
|
||
class Post(BaseModel): | ||
uri = peewee.CharField(index=True) | ||
cid = peewee.CharField() | ||
reply_parent = peewee.CharField(null=True, default=None) | ||
reply_root = peewee.CharField(null=True, default=None) | ||
indexed_at = peewee.DateTimeField(default=datetime.now(timezone.utc), index=True) | ||
author = peewee.CharField(null=True, default=None, index=True) | ||
interactions = peewee.BigIntegerField(default=0, index=True) | ||
|
||
class SubscriptionState(BaseModel): | ||
service = peewee.CharField(unique=True) | ||
cursor = peewee.BigIntegerField() | ||
|
||
class SessionState(BaseModel): | ||
service = peewee.CharField(unique=True) | ||
session_string = peewee.TextField(null=True) | ||
|
||
# table for storing dids | ||
class Requests(BaseModel): | ||
indexed_at = peewee.DateTimeField(default=datetime.now(timezone.utc), index=True) | ||
did = peewee.CharField(null=True, default=None, index=True) |
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,5 @@ | ||
atproto | ||
apscheduler | ||
peewee | ||
psycopg2-binary | ||
python-dotenv |
Empty file.
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,38 @@ | ||
import os | ||
|
||
SERVICE_DID = os.environ.get('SERVICE_DID', None) | ||
HOSTNAME = os.environ.get('HOSTNAME', None) | ||
HANDLE = os.environ.get('HANDLE', None) | ||
PASSWORD = os.environ.get('PASSWORD', None) | ||
POSTGRES_USER = os.environ.get('POSTGRES_USER', None) | ||
POSTGRES_PASSWORD = os.environ.get('POSTGRES_PASSWORD', None) | ||
POSTGRES_DB = os.environ.get('POSTGRES_DB', None) | ||
|
||
if POSTGRES_USER is None: | ||
raise RuntimeError('You should set "POSTGRES_USER" environment variable first.') | ||
|
||
if POSTGRES_PASSWORD is None: | ||
raise RuntimeError('You should set "POSTGRES_PASSWORD" environment variable first.') | ||
|
||
if POSTGRES_DB is None: | ||
raise RuntimeError('You should set "POSTGRES_DB" environment variable first.') | ||
|
||
if HOSTNAME is None: | ||
raise RuntimeError('You should set "HOSTNAME" environment variable first.') | ||
|
||
if SERVICE_DID is None: | ||
SERVICE_DID = f'did:web:{HOSTNAME}' | ||
|
||
|
||
CHRONOLOGICAL_TRENDING_URI = os.environ.get('CHRONOLOGICAL_TRENDING_URI') | ||
if CHRONOLOGICAL_TRENDING_URI is None: | ||
raise RuntimeError('Publish your feed first (run publish_feed.py) to obtain Feed URI. ' | ||
'Set this URI to "CHRONOLOGICAL_TRENDING_URI" environment variable.') | ||
|
||
# logger.info(f'HANDLE: {HANDLE}') | ||
# logger.info(f'PASSWORD: {PASSWORD}') | ||
if HANDLE is None: | ||
raise RuntimeError('You should set "HANDLE" environment variable first.') | ||
|
||
if PASSWORD is None: | ||
raise RuntimeError('You should set "PASSWORD" environment variable first.') |
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,8 @@ | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig( | ||
level=logging.INFO, | ||
format='[%(asctime)s] [%(levelname)s] %(message)s', | ||
datefmt='%H:%M:%S' | ||
) |