Commit e1b7f01e authored by root's avatar root

Added fully emoji entity handle

parent 859a3c36
import re
from sys import stdout
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
\ No newline at end of file
# Entity base
Base = declarative_base()
# Emoji reencoding for DB -> emoji_pattern.sub(r'', text)
emoji_pattern = re.compile("["
u"\U0001F600-\U0001F64F" # emoticons
u"\U0001F300-\U0001F5FF" # symbols & pictographs
u"\U0001F680-\U0001F6FF" # transport & map symbols
u"\U0001F1E0-\U0001F1FF" # flags (iOS)
"]+", flags=re.UNICODE)
def emoji_decode(text):
""" Decodes a string for db by removing emojis """
text = emoji_pattern.sub(r':)', str(text))
text = text.encode(stdout.encoding, errors="replace")
return text
......@@ -14,8 +14,8 @@ class Database:
create_database(connection_str)
self._engine = create_engine(
connection_str,
encoding="latin1",
echo=True)
encoding="utf8",
echo=True) #latin1
self._session = scoped_session(sessionmaker(bind=self._engine))
Base.metadata.create_all(self._engine)
......
""" Just add goup chat to db, remember that. """
from sys import stdout
from DB.base import Base
from DB.base import Base, emoji_decode
from Model.user import User
from sqlalchemy import Column, Integer, BigInteger, String, Boolean, ForeignKey
from sqlalchemy.orm import relationship
......@@ -23,10 +23,10 @@ class Chat(Base):
@staticmethod
def create_from_tg(tg_chat, arg1=None, arg2=None):
# Normalisize
title = str(tg_chat.title).encode(stdout.encoding, errors="replace")
description = str(tg_chat.description).encode(stdout.encoding, errors="replace")
# chat_id dont have to be set
# Normalisize
title = emoji_decode(tg_chat.title)
description = emoji_decode(tg_chat.description)
return Chat(
id=tg_chat.id,
username=tg_chat.username,
......
import datetime
from sys import stdout
from DB.base import Base
from DB.base import Base, emoji_decode
from Model.chat import Chat
from Model.user import User
from sqlalchemy import Column, Integer, BigInteger, String, Boolean, ForeignKey
......@@ -19,9 +19,9 @@ class Message(Base):
@staticmethod
def create_from_tg(tg_message, chat_id=None, user_id=None):
# Normalisize
text = str(tg_message.text).encode(stdout.encoding, errors="replace")
# message_id dont have to be set
# Normalisize
text = emoji_decode(tg_message.text)
try:
date = tg_message.date.strftime("%m/%d/%Y,%H:%M:%S")
except Exception:
......
from sys import stdout
from DB.base import Base
from DB.base import Base, emoji_decode
from Model.user import User
from Model.poll_option import PollOption
from sqlalchemy import Column, Integer, BigInteger, String, Boolean, ForeignKey
......@@ -24,7 +24,7 @@ class Poll(Base):
@staticmethod
def create_from_tg(tg_poll, user_id, date=None):
# Normalisize
question = str(tg_poll.question).encode(stdout.encoding, errors="replace")
question = emoji_decode(tg_poll.question)
#options = [Option.create_from_tg(o) for o in tg_poll.options]
#correct_option = (o for o in options if o.id == tg_poll.correct_option_id)
return Poll(
......
from sys import stdout
from DB.base import Base
from DB.base import Base, emoji_decode
from sqlalchemy import Column, Integer, String, BigInteger, Boolean, ForeignKey
from sqlalchemy.orm import relationship
......@@ -19,7 +19,7 @@ class PollOption(Base):
@staticmethod
def create_from_tg(tg_option, poll_id, arg2=None):
# Normalisize
text = str(tg_option.text).encode(stdout.encoding, errors="replace")
text = emoji_decode(tg_option.text)
return PollOption(
text=text,
voter_count=tg_option.voter_count,
......
from sys import stdout
from DB.base import Base
from DB.base import Base, emoji_decode
from sqlalchemy import Column, Integer, String, BigInteger, Boolean, ForeignKey
from sqlalchemy.orm import relationship
......@@ -23,12 +23,12 @@ class User(Base):
@staticmethod
def create_from_tg(tg_user, arg1=None, arg2=None):
# Normalisize
username = str(tg_user.username).encode(stdout.encoding, errors="replace")
name = str(tg_user.name).encode(stdout.encoding, errors="replace")
first_name = str(tg_user.first_name).encode(stdout.encoding, errors="replace")
last_name = str(tg_user.last_name).encode(stdout.encoding, errors="replace")
# user_id dont have to be set
# Normalisize
username = emoji_decode(tg_user.username)
name = emoji_decode(tg_user.name)
first_name = emoji_decode(tg_user.first_name)
last_name = emoji_decode(tg_user.last_name)
return User(
id=tg_user.id,
name=name,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment