mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 18:07:02 +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')
|
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='user_device_details')
|
||||||
"""Device ID"""
|
"""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)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
updated_at = models.DateTimeField(auto_now=True)
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
import oss2
|
import oss2
|
||||||
"""Import setting"""
|
"""Import setting"""
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
import logging
|
||||||
|
import requests
|
||||||
"""Import tempfile"""
|
"""Import tempfile"""
|
||||||
import tempfile
|
import tempfile
|
||||||
# Import date time module's function
|
# Import date time module's function
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
# Import real time client module
|
|
||||||
import ntplib
|
|
||||||
# import Number constant
|
# import Number constant
|
||||||
from base.constants import NUMBER
|
from base.constants import NUMBER
|
||||||
# Import Junior's model
|
# Import Junior's model
|
||||||
@ -44,16 +44,19 @@ def upload_image_to_alibaba(image, filename):
|
|||||||
new_filename = filename.replace(' ', '%20')
|
new_filename = filename.replace(' ', '%20')
|
||||||
return f"https://{settings.ALIYUN_OSS_BUCKET_NAME}.{settings.ALIYUN_OSS_ENDPOINT}/{new_filename}"
|
return f"https://{settings.ALIYUN_OSS_BUCKET_NAME}.{settings.ALIYUN_OSS_ENDPOINT}/{new_filename}"
|
||||||
|
|
||||||
def real_time():
|
|
||||||
""" real time """
|
def real_time(timezone='Asia/Riyadh'):
|
||||||
# Fetch real time.
|
url = f'http://worldtimeapi.org/api/timezone/{timezone}'
|
||||||
# time is not depend on system time
|
response = requests.get(url)
|
||||||
# Get the current datetime
|
if response.status_code == 200:
|
||||||
ntp_client = ntplib.NTPClient()
|
data = response.json()
|
||||||
ntp_server = 'pool.ntp.org'
|
time_str = data['datetime']
|
||||||
response = ntp_client.request(ntp_server)
|
realtime = datetime.fromisoformat(time_str.replace('Z', '+00:00')).replace(tzinfo=None)
|
||||||
current_datetime = datetime.fromtimestamp(response.tx_time)
|
return realtime
|
||||||
return current_datetime
|
else:
|
||||||
|
logging.error("Could not fetch error")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def convert_timedelta_into_datetime(time_difference):
|
def convert_timedelta_into_datetime(time_difference):
|
||||||
"""convert date time"""
|
"""convert date time"""
|
||||||
|
Reference in New Issue
Block a user