mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 10:05:21 +00:00
jira-32 list of all task of junior API, changes in Search task API
This commit is contained in:
@ -5,6 +5,12 @@ import oss2
|
||||
from django.conf import settings
|
||||
"""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
|
||||
|
||||
# Define upload image on
|
||||
# ali baba cloud
|
||||
@ -13,6 +19,8 @@ import tempfile
|
||||
# then check bucket name
|
||||
# then upload on ali baba
|
||||
# bucket and reform the image url"""
|
||||
# fetch real time data without depend on system time
|
||||
# convert time delta into date time object
|
||||
|
||||
def upload_image_to_alibaba(image, filename):
|
||||
"""upload image on oss alibaba bucket"""
|
||||
@ -30,3 +38,22 @@ 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():
|
||||
# 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 convert_timedelta_into_datetime(time_difference):
|
||||
# convert timedelta into datetime format
|
||||
hours = time_difference.seconds // NUMBER['thirty_six_hundred']
|
||||
minutes = (time_difference.seconds // NUMBER['sixty']) % NUMBER['sixty']
|
||||
seconds = time_difference.seconds % NUMBER['sixty']
|
||||
microseconds = time_difference.microseconds
|
||||
# Create a new time object with the extracted time components
|
||||
time_only = time(hours, minutes, seconds, microseconds)
|
||||
return time_only
|
||||
|
Reference in New Issue
Block a user