mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Add diario
This commit is contained in:
parent
901cb874a8
commit
e42885308c
2 changed files with 39 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
config.ini
|
config.ini
|
||||||
.idea/
|
.idea/
|
||||||
__pycache__
|
__pycache__
|
||||||
|
diario.json
|
37
db.py
37
db.py
|
@ -1,4 +1,5 @@
|
||||||
import time
|
import time
|
||||||
|
import datetime
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker, relationship
|
from sqlalchemy.orm import sessionmaker, relationship
|
||||||
from sqlalchemy import Column, BigInteger, Integer, String, Numeric, DateTime, ForeignKey, Float, Enum, create_engine, UniqueConstraint
|
from sqlalchemy import Column, BigInteger, Integer, String, Numeric, DateTime, ForeignKey, Float, Enum, create_engine, UniqueConstraint
|
||||||
|
@ -519,6 +520,42 @@ class Overwatch(Base):
|
||||||
self.level = j["prestige"] * 100 + j["level"]
|
self.level = j["prestige"] * 100 + j["level"]
|
||||||
self.rank = j["comprank"]
|
self.rank = j["comprank"]
|
||||||
|
|
||||||
|
|
||||||
|
class Diario(Base):
|
||||||
|
__tablename__ = "diario"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True)
|
||||||
|
timestamp = Column(DateTime, nullable=False)
|
||||||
|
saver_id = Column(Integer, ForeignKey("telegram.telegram_id"))
|
||||||
|
saver = relationship("Telegram", foreign_keys=saver_id)
|
||||||
|
author_id = Column(Integer, ForeignKey("telegram.telegram_id"))
|
||||||
|
author = relationship("Telegram", foreign_keys=author_id)
|
||||||
|
text = Column(String)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<Diario {self.id}>"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.id} - {self.timestamp} - {self.author}: {self.text}"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def import_from_json(file):
|
||||||
|
import json
|
||||||
|
file = open(file, "r")
|
||||||
|
j = json.load(file)
|
||||||
|
for entry in j:
|
||||||
|
if "sender" in entry:
|
||||||
|
author = session.query(Telegram).filter_by(username=entry["sender"].lstrip("@")).first()
|
||||||
|
else:
|
||||||
|
author = None
|
||||||
|
d = Diario(timestamp=datetime.datetime.fromtimestamp(float(entry["timestamp"])),
|
||||||
|
author=author,
|
||||||
|
text=entry["text"])
|
||||||
|
print(d)
|
||||||
|
session.add(d)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
# If run as script, create all the tables in the db
|
# If run as script, create all the tables in the db
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
Loading…
Reference in a new issue