Taking a screenshot of uploaded files using Python/Heroku - python

There are design files uploaded/downloaded by users on a website. For every uploaded file, I would like to show a screenshot of the file so people can see an image before they download them.
They are very esoteric files though that need to be opened in particular design tools. (I even don't have the software to run them on my local machine).
My thinking is that I can run a virtual machine that has these programs installed, programmatically open the files, and then take a screenshot of the opened file and save a thumbnail. But I want to do this when the user uploads the design file.
But someone told me PIL could do this. But I investigated and can't seem to figure out any documentation on how to go about this.
Has anyone ever done something like this before? What is the best approach?

Related

google colab - Download files synchronously

I am using this code snippet to download files from google colab:
from google.colab import files
files.download("sample_data/california_housing_train.csv")
print("done")
But the output is
done
Downloading "california_housing_train.csv"
The download function is asynchronous. This may not seem much but actually the function is being run in a loop so after starting download some external libraries are called in starting of next iteration and it clears the output. Also, I have tested it many times that in case the output is cleared before the file is downloaded, it will not download.
Also, please dont suggest downloading it from the file menu. There are going to be a lot of files so it has to be programmatically. Also, please dont suggest the method to zip it programmatically and then download it from file browser, as i have to download the files after each iteration bcz I am using a workaround for colab's "are you still there" but it stills considers my session idle and deleted runtime and all the files are lost.
Thank you in advance. Sorry for any grammatical errors.
Edit:
I have also tried using sleep method but that didn't work as sometimes the files take more time to load despite very very good internet connection compared to the size of the file. Keeping very high values of sleep() is not good as it is not the best way. still, if i find nothing else i will use sleep() only.
OK, so I found a temporary workaround which is not wholly programmable and may need manual downloading in cases where runtime gets deleted due to inactivity before executing whole program.
So, my idea is to mount google drive on the runtime and copy the files to a folder in google drive after each execution. In the end zip the folder in drive and download it by files.download(path to drive zip) . In case the runtime was not able to execute whole code and dies prematurely, the folder in the google drive will remain unlike it being deleted when runtime is destroyed, so we can go and manually download the folder from google drive.
If anyone else has a better solution, please let me know.

How to set access rights to windows folder and files using python?

I need to use python to configure the file's access rights (I don't know exactly what it's called attached a screenshot). I have an application installer and it creates a folder in the system, this folder needs to be protected from the user, that is, to make it so that he could not edit, view and delete it. I've read a lot of articles, tried a lot of options, but unfortunately everything is even. os.chmod was mentioned a lot, but all the result I got from it was setting up a "read-only" file. How can I prevent the user from interacting with the folder and its files so that he could not remove the lock? But at the same time we should be able to interact with files using python scripts?

Pytube direct video downloading without any folder

I finished a streamlit app that basically downloads video and audio using pytube, and currently, I want to deploy it so that me and the others can use it on their phones, comps, and so on. However, when I deploy it and use it from another device, even though the model itself works, the file is not downloaded. Therefore I want to make it to be downloaded directly from chrome. (like the way that pictures and others are downloaded from chrome). Is there any particular method or trick for that? Thanks
you need to provide code of your app. For specify a download directory in pytube you need to write
directory = '/home/user/Documents'
file.download(directory)

How to download numpy array files from an online drive

I have a dataset contains hundreds of numpy arrays looks like this,
I am trying to save them to an online drive so that I can run the code with this dataset remotely from a sever. I cannot access the drive of the server but can only run code script and access the terminal. So I have tried with google drive and Onedrive, and looked up how to generate a direct download link from those drives but it did not work.
In short, I need to be able to get those files from my python scripts. Could anyone give some hints?
You can get the download URLs very easily from Drive. I assume that you already uploaded the files into a Drive folder. Then you can easily set up a scenario to download the files on Python. First you would need an environment on Python to connect to Drive. If you don't currently have one, you can follow this guide. That guide will install the required libraries, credentials and run a sample script. Once you can run the sample script you can make minor modifications to reach your goal.
To download the files you are going to need their ids. I am assuming that you already know them, but if you don't you could retrieve them by doing a Files.list on the folder where you keep the files. To do so you can use '{ FOLDER ID }' in parents as the q parameter.
To download the files you only have to run a Files.get request by providing the file id. You will find the download URL on the webContentLink property. Feel free to leave a comment if you need further clarifications.

How to run Github code (with python) automatically on MyBinder or Google Colab without downloading the Sample code?

MyBinder and Colaboratory are feasible to allow people to run our examples from the website directly in their browser, without any download required.
When I work on the Binder, our data to be loaded takes a huge time. So, I need to run python code on the website directly.
I'm not sure whether I totally get the question. If you want to avoid having to download the data from another source, you can add the data into you git repo which you use to start Binder. It should look something like this: https://github.com/lschmiddey/book_recommender_voila
However, if your dataset is too big to be uploaded to your git repo, you have to get the data onto the provided Binder server somehow. So you usually have to download the data onto your Binder Server so that other users can work on your notebook.

Categories