Skip to content

Commit

Permalink
Merge pull request #94 from ufoptg/patch-7
Browse files Browse the repository at this point in the history
functions_date.py
  • Loading branch information
xtsea authored Sep 16, 2024
2 parents 4a49d26 + d927a9c commit 3fc889b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion RyuzakiLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from .extreme.userinfo import TelegramUserInfo
from .extreme.webshot import WebShotUrl
from .fastapi import FastAPISuper
from .functions_date import UserDateEstimator
from .hackertools.blackbox import Blackbox
from .hackertools.chatgpt import RendyDevChat
from .hackertools.cloudflare import CloudFlare
Expand Down Expand Up @@ -66,7 +67,6 @@
from .story import *
from .system.read import System
from .tr import *
from .functions_date import UserDateEstimator


class AwesomeCoding(BaseModel):
Expand Down
23 changes: 14 additions & 9 deletions RyuzakiLib/functions_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
# requires: python-dateutil

import time
from datetime import datetime

import numpy as np
from dateutil.relativedelta import relativedelta
from datetime import datetime

data = {
"7117444122": 1723429195,
"6602485156": 1723148395,
"5396587273": 1648014800,
"5336336790": 1646368100,
"4317845111": 1620028800,
Expand All @@ -34,29 +37,31 @@
}

class UserDateEstimator:
def __init__(self, order = 3):
self.order = 3

def __init__(self, order=3):
self.order = order
self.x, self.y = self._unpack_data()
self._func = self._fit_data()

def _unpack_data(self):
x_data = np.array(list(map(int, data.keys())))
y_data = np.array(list(data.values()))
return (x_data, y_data)
return x_data, y_data

def _fit_data(self):
fitted = np.polyfit(self.x, self.y, self.order)
return np.poly1d(fitted)

def func(self, tg_id: int):
# Check if tg_id exists in the data
if str(tg_id) in data:
return data[str(tg_id)] # Return exact value if found
value = self._func(tg_id)
if value > time.time():
value = time.time()
return value

def time_format(self, unix_time, fmt="%Y-%m-%d"):
result = [str(datetime.utcfromtimestamp(unix_time).strftime(fmt))]
def time_format(self, unix_time):
formatted_date = datetime.utcfromtimestamp(unix_time).strftime("%Y-%m-%d %H:%M:%S")
d = relativedelta(datetime.now(), datetime.utcfromtimestamp(unix_time))
result.append(f"{d.years} year{'s' if d.years != 1 else ''}, {d.months} month{'s' if d.months != 1 else ''}, {d.days} day{'s' if d.days != 1 else ''}")
return result
age = f"{d.years} year{'s' if d.years != 1 else ''}, {d.months} month{'s' if d.months != 1 else ''}, {d.days} day{'s' if d.days != 1 else ''}"
return formatted_date, age

0 comments on commit 3fc889b

Please sign in to comment.