Skip to content
Open
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
47 changes: 46 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pandas = "^2.1.0"
python-decouple = "^3.8"
hugchat = "^0.2.2"
dependencies = "^7.7.0"
pendulum = "^2.1.2"


[tool.poetry.group.dev.dependencies]
Expand Down
82 changes: 58 additions & 24 deletions src/repositories/scrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any

import pandas as pd
import pendulum
import requests
from repositories.texts_database import TextsDatabaseRepository

Expand Down Expand Up @@ -33,7 +34,7 @@ def __init__(self, scrapper_email: str, scrapper_password: str) -> None:

self.token = response.json()["accessToken"]
self.biography_id = response.json()["projectsList"][0]["_id"]
# self.userId = response.json()["user"]["_id"]
self.userId = response.json()["user"]["_id"]

def post(self, url: str, data: dict[str, Any]) -> requests.Response:
return self.__session.post(
Expand All @@ -51,6 +52,13 @@ class Scrapper:
TRANSCRIPT_URL = (
"https://redaction-backend-prod.herokuapp.com/platform/transcripts/get-model"
)
MASTER_URL = (
"https://redaction-backend-prod.herokuapp.com/platform/masters/get-model"
)
CREATE_STORY = (
"https://redaction-backend-prod.herokuapp.com/platform/chapters/create-new"
)
SAVE_TEXT_URL = "https://redaction-backend-prod.herokuapp.com/platform/masters/save-text-modifications"

def __init__(
self,
Expand All @@ -60,29 +68,6 @@ def __init__(
self.__connection = entoureo_connection
self.__texts_database = texts_database

# def login(self) -> None:
# if not self.__email or not self.__password:
# print(
# f"Found {self.__email} for username and {self.__password} "
# f"for password. Need to set them in the .env file"
# )
# return

# payload = {"email": self.__email, "password": self.__password}

# print("Login to entoureo ...")
# response = self.__session.post(self.LOGIN_URL, data=payload)
# assert (
# 200 <= response.status_code < 300
# ), f"The request wasn't valid, got status code {response.status_code}"
# print(
# response.status_code
# ) # If the request went Ok we usually get a 200 status.

# self.token = response.json()["accessToken"]
# self.biography_id = response.json()["projectsList"][0]["_id"]
# self.userId = response.json()["user"]["_id"]

def get_all_chapters(self) -> pd.DataFrame:
payload = {"biographyId": self.__connection.biography_id}

Expand Down Expand Up @@ -160,3 +145,52 @@ def get_transcription(

transcriptName = response.json()["transcript"]["title"]
return (transcriptName, transcriptData)

def create_new_story(
self,
name: str,
):
response = self.__connection.post(
url=self.CREATE_STORY,
data={
"biographyId": self.__connection.biography_id,
"userId": self.__connection.userId,
"newChapterTitle": name,
},
)
print("Response story creation: ", response.status_code)

def save_to_story(self, chapter_id: str, text: str):
# first step get what they call the "master" info
response = self.__connection.post(
url=self.MASTER_URL,
data={
"chapterId": chapter_id,
"userId": self.__connection.userId,
},
)
assert (
200 <= response.status_code < 300
), f"The request wasn't valid, got status code {response.status_code}"
print("Response code: ", response.status_code)
master = response.json()["master"]
master["currentText"] = text
# date using this format: 2021-09-28T14:00:00.000Z
# master["dateOfLastModification"] = pendulum.now("UTC").to_iso8601_string()
import json

print(json.dumps(master, indent=4))
# second step save the text
response = self.__connection.post(
url=self.SAVE_TEXT_URL,
data={
"chapterId": chapter_id,
"userId": self.__connection.userId,
"master": master,
},
)
assert (
200 <= response.status_code < 300
), f"The request wasn't valid, got status code {response.status_code}"
print("Response code: ", response.status_code)
print(response.json())
15 changes: 8 additions & 7 deletions src/scraping_test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@


def main():
chapters = Container.scrapper.get_all_chapters()
transcriptions = Container.scrapper.get_chapter_data(chapters.loc[0, "_id"])
# chapters = Container.scrapper.get_all_chapters()
# transcriptions = Container.scrapper.get_chapter_data(chapters.loc[0, "_id"])

transcriptName, transcriptData = Container.scrapper.get_transcription(
transcriptions[0]["_id"], chapters.loc[0, "_id"]
)
print(transcriptName)
print(transcriptData)
# transcriptName, transcriptData = Container.scrapper.get_transcription(
# transcriptions[0]["_id"], chapters.loc[0, "_id"]
# )
# print(transcriptName)
# print(transcriptData)
Container.scrapper.save_to_story("6529456e77d0b130fde581ac", "rwrite this shit")


if __name__ == "__main__":
Expand Down