Python: upload images - python

Can python upload images onto the internet and provide a URL for it? For example is it possible for python to upload an image onto photobucket or any other uploading image service and then retreive the URL for it?

Certainly. You'll need to find an image hosting service with an API (hint: Flickr), and then write some Python code to interact with it (hint: XML-RPC).
Pseudocode
import xmlrpclib
with open( "..." ) as imagelist:
for image in imagelist:
message = xmlrpclib.make_some_message_or_other
response = message.send( )
response.parse( )
You'll need a more specific question if you want a more specific answer!

Sure!
To do it, you basically have to have Python pretend to be a web browser. You need to go get the upload form, fill in all the fields, and pick your image. Then you need to submit the form data, uploading the image. Once that's done, you need to get the "upload complete" page from the site, and find the URL where the image went.
A good library to start with might be the Python version of Perl's famous WWW::Mechanize module. The library is basically a programmable Web browser that you can script in Python.
EDIT: If you plan to do this a lot, you probably do want to use an actual supported API. Otherwise the image hoster might get mad that your python bot is spamming their site.

Related

Retrieving images loaded in the browser

The following code works great for fetching static images:
import urllib
urllib.urlretrieve({SOME_URL}, "00000001.jpg")
I'd however like to fetch all media that I can load on WhatsApp Web. For instance, looking at the source of a conversation that's fully loaded on my screen, I can see the image URLs such as blob:https://web.whatsapp.com/a2e9249a-365c-4ce7-a3ce-795be018400e – that link/image can actually be opened in a separate browser tab.
If I replace {SOME_URL} with that link, Python doesn't recognise blob as a valid HTTP request. I have kept my browser with WhatsApp Web loaded in the background as I assume those links may actually change every time I load the conversation. But the first problem is trying to find a urlretrieve equivalent. Any thoughts? Thank you!

Access html drag and drop with python

I have found a very nice algorithm for image classification (https://everypixel.com/aesthetics) and was wondering if its possible to upload image files to the webpage with python. They are using a drag and drop system for the image files. Because the algorithm tags those uploaded pictures, the possibility of automatic upload would be very nice.
Python is just a language and not a framework. This means it is not sufficient to be a web server(something that will accept a request and respond to it).
So you need to use a server like flask to accept the request and implement your algorithm there.To attach a file you need to implement a frontend as well.

Can I post an image file on the public web server with python?

I have a python program that draws a physical network topology from gns3 using CDP and saves it after every 1 minute as a .png image file. I'm wondering if there is a way to post that image in a some kind of web-server so that I would be able to access it remotly with browser. Thank you
If the web server is running locally, all you need is to save it to the right directory.
If you have a web space somewhere, you can use FTP for uploading as described for example in this previous question.
You can also upload it directly to some image hosting web service, where you could then use their UI to nicely browse, categorize or delete the images as required -- you could look at some open source image uploading script like uimge for inspiration.

Saving emails for later view

I need to save emails I receive so that the user can view them later on. They need to be saved in such a way that the images will remain even if their links a re broken (e.g. for the images that are link and not attachments, upload them to S3 and change the links to point to them).
Can anyone recommend a library that will help me achieve that?
I was thinking of two approaches:
1) Save the email to PDF - but I have no idea how to make it correctly include the images.
2) Save the original email and render it on the client, but then it doe snot show the attached images.
Any one of those will do with preference to the first option. If its the first option then I can write it on my RoR server or as an external Python service. If its the sercond I have to write it to work on RoR.
I am aware that this question is similar to: Best way to save email, including images and HTML data, using Java Mail API?
but I need to do it on Rails not Java.
Thank you!
Why not just have an auto-forwarder to a separate account? That way they would effectively be bcc'd on everything you get. I know Gmail can easily do that with filters.
Another option is forwarding the emails to a 'read it later' service and let their api do the heavy lifting. Not sure if they keep the attachment, but it is worth a look.

Link to force download of external image with Python web app

I've got a Python (Wep2py) web app that generates QR codes using the Google chart API. The app displays the QR code on the screen, and I want to offer a link to download it. Considering the images are not on my server, what are my options?
Example image url:
https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=Hello%20world
EDIT:
I've seen mention of using the header Content-disposition: attachment; to force a download dialog. Does anyone know if this header can be applied to external resources?
Download QR code here
Edit: If the browser of your user is able to handle the mimetype Google sends for the image, the browser will handle it. There is not much you can do about this which is a Good ThingTM.

Categories

Resources