how to add hour onto time script in linux - linux

I have a webcam that uploads a pic to a webpage every 5 minutes and beneath it is some code to upload a timestamp. Recently I have noticed the timestamp is an hour out and Ive checked the linux server, webcam taking images and they have the correct time so not sure what has happened. I suspect its some daylight saving issue but I cant find it so just want to do a temp fix for now.
Heres the code I use to timestamp the image, how can I add an hour onto this? Everything I have tried just results in it not showing the timestamp at all?
echo "- Image Uploaded: " . date ("F d Y H:i:s", filemtime($filename));

Assuming this is php, you can set a timezone in your script
with eg
date_default_timezone_set('Europe/Amsterdam');
See here for the list of timezones.

Related

How to calculate utc in local time on ubuntu with python 3.8

I have a web application writen in python 3.8 running on an ubuntu server (18.04).
Requests to the server are processed by a nginx server.
It is possible to upload pdf and excel files and the website should show the date and time the files were uploaded.
This is working but the utc time is shown and I want the website to show the actual local time (Europe/Berlin UTC +1/+2). So I just tried to convert the time within the python code:
utc_diff = 1
cur_time = time.time()
if time.localtime(cur_time).tm_isdst: # check summer / winter time
>> utc_diff = 2
... (datetime.fromtimestamp(round(timestamp)) + timedelta(hours=utc_diff))
or
utc = datetime.utcnow()
ltz = datetime.astimezone(utc)
diff = str(ltz).split("+")
diff = diff[1].split(":")
... datetime.fromtimestamp(round(timestamp)) + timedelta(hours=int(diff))
The problem is that I just can calcualte for example +2 hours but if I want to use any fucntions of the time or datetime module it just works on my local windows pc but not on the server.
The line datetime.fromtimestamp(round(timestamp)) + timedelta(hours=int(diff)) is working locally and on the server.
How I have to code this to make it work on the server?
I don't think you want to do the time offset by hand. I think you want soemthing more like:
import time
now = time.time()
print(time.strftime("%H:%M:%S", time.gmtime(now)))
print(time.strftime("%H:%M:%S", time.localtime(now)))

Google Drive File Stream files creation date

I know it has been asked a few times already, but - not in this context I think and other questions have been asked few years ago already, so I'm hoping maybe something changed.
So my issue is - I am uploading files to the Google Drive using Google Drive File Stream. However, while the uploading goes smoothly, I have a problem with files creation date - it is always changed to the timestamp of the time the file got uploaded, not the actual, local file creation date. It is a serious problem, as I am going to use this to back-up huge amounts of data and preserve all the meta-data I can and the creation date is crucial. Is there a way to either upload it with the creation date intact, or to change it after the upload? From what I've seen this seems not to be possible, but I have to try and make it work. Any help and insight will be appreciated. I'm using the Drive File Stream with Python.
EDIT: I didn't make it clear enough - the issue here is that I don't want to use Google Drive API at all, but rather deal with this using only Google Drive File Stream interface if it's possible.
create
If you check the documentation for files.create You will find that acceptable metadata for file creation does include a createdTime
You should then just add this to the metadata you use when uploading the file. As you did not post your code I have grabbed the standard example from the documentation and added the created time as follows.
file_metadata = {'name': 'photo.jpg', 'createdTime': 'THETIME'}
media = MediaFileUpload('files/photo.jpg', mimetype='image/jpeg')
file = drive_service.files().create(body=file_metadata,
media_body=media,
fields='id').execute()
print 'File ID: %s' % file.get('id')
Update
In the event that you want to update the ones you have already created you could use the following method.
If you check the documentation for file create you will find that the response is just a File resource
If you check file resource you will see that CreatedTime is write able.
You should run a file.update and reset the createdTime to the proper time.

Eyed3 write ID3 YEAR tag to Mp3

Using eyed3 I have no problems setting all other tags than the YEAR tag, also there is no problem reading the .getBestDate() put I can't write the tag.
import eyed3
audiofile = eyed3.load("Example.mp3")
print(audiofile.tag.getBestDate()) # returns the Year
audiofile.initTag()
audiofile.tag.xxxxxxxxx = ("1843") # how to write the Year?
audiofile.tag.save()
I have trawled the manual https://buildmedia.readthedocs.org/media/pdf/eyed3/latest/eyed3.pdf and google but just can't figure it out.
The year tag is simply year :
audiofile.tag.year
But I've never been able to get it to successfully add the year, never see any errors, it's just always blank.

How to make python wait for the exact amount of time taken to upload certain number of files?

I have been working with python for only a couple of months. I have a list of files I want to upload using Selenium and Python. Here is the code:
for k in os.listdir('../Uploads'):
if fnmatch.fnmatch(k, '*.pdf'):
driver.find_element_by_xpath('#xpath').send_keys(os.path.abspath("../Uploads" + "\\" + k))
However, with the new update of Chrome (77) and chromedriver, python doesn't wait for a file to be uploaded and moves on to the rest of the code instantly. I added time.sleep(10) after the for... loop. Python then waited for 10 secs for all the files in the directory to upload, which may or may not be sufficient for all the uploads, depending on the file sizes and number of files.
I also tried:
for k in os.listdir('../Uploads'):
if fnmatch.fnmatch(k, '*.pdf'):
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,'#xpath'))).send_keys(os.path.abspath("../Uploads"+"\\"+k))
but python waited for 10 secs and gave a timeout error without uploading any file.
Please suggest a way around this.
Thank you so much!

Change the path of CSV file every day at a specified hour and minute node.js

New to node.js. My requirement is to change file name of a CSV file to a different path (new file) every day at 15 minutes past midnight. Presently using fast-csv to write the output. How can I change the path of the file dynamically to another path and CSV file at the above mentioned time, such that the new file takes over the writing of output and the previous one is saved and closed. How can I accomplish this?
Edit: I can use node-schedule for the scheduling part.
For the time use https://www.npmjs.com/package/node-schedule
var event = schedule.scheduleJob("0 15 0 * * 0-6", function() {
yourFunctionToChangeTheCSVPath();
});
This should be 15 past midnight.

Resources