mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 10:05:21 +00:00
real time changes
This commit is contained in:
18
account/migrations/0009_alter_userdevicedetails_device_id.py
Normal file
18
account/migrations/0009_alter_userdevicedetails_device_id.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.2 on 2023-07-20 11:38
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('account', '0008_userdevicedetails'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='userdevicedetails',
|
||||
name='device_id',
|
||||
field=models.CharField(blank=True, max_length=500, null=True),
|
||||
),
|
||||
]
|
@ -152,7 +152,7 @@ class UserDeviceDetails(models.Model):
|
||||
"""
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='user_device_details')
|
||||
"""Device ID"""
|
||||
device_id = models.CharField(max_length=500)
|
||||
device_id = models.CharField(max_length=500, null=True, blank=True)
|
||||
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
@ -3,12 +3,12 @@
|
||||
import oss2
|
||||
"""Import setting"""
|
||||
from django.conf import settings
|
||||
import logging
|
||||
import requests
|
||||
"""Import tempfile"""
|
||||
import tempfile
|
||||
# Import date time module's function
|
||||
from datetime import datetime, time
|
||||
# Import real time client module
|
||||
import ntplib
|
||||
# import Number constant
|
||||
from base.constants import NUMBER
|
||||
# Import Junior's model
|
||||
@ -44,16 +44,19 @@ def upload_image_to_alibaba(image, filename):
|
||||
new_filename = filename.replace(' ', '%20')
|
||||
return f"https://{settings.ALIYUN_OSS_BUCKET_NAME}.{settings.ALIYUN_OSS_ENDPOINT}/{new_filename}"
|
||||
|
||||
def real_time():
|
||||
""" real time """
|
||||
# Fetch real time.
|
||||
# time is not depend on system time
|
||||
# Get the current datetime
|
||||
ntp_client = ntplib.NTPClient()
|
||||
ntp_server = 'pool.ntp.org'
|
||||
response = ntp_client.request(ntp_server)
|
||||
current_datetime = datetime.fromtimestamp(response.tx_time)
|
||||
return current_datetime
|
||||
|
||||
def real_time(timezone='Asia/Riyadh'):
|
||||
url = f'http://worldtimeapi.org/api/timezone/{timezone}'
|
||||
response = requests.get(url)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
time_str = data['datetime']
|
||||
realtime = datetime.fromisoformat(time_str.replace('Z', '+00:00')).replace(tzinfo=None)
|
||||
return realtime
|
||||
else:
|
||||
logging.error("Could not fetch error")
|
||||
return None
|
||||
|
||||
|
||||
def convert_timedelta_into_datetime(time_difference):
|
||||
"""convert date time"""
|
||||
|
Reference in New Issue
Block a user