Python Forum
Download some JPG files and make it a single PDF & share it - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Download some JPG files and make it a single PDF & share it (/thread-28631.html)



Download some JPG files and make it a single PDF & share it - rompdeck - Jul-27-2020

I download some jpg files (A4 size) from a website and convert all the files into a single pdf file and email it.

The jpg files are in a url format of:

http://URL.com/RPT/2020/07/26/<page no>

The date today is 2020/7/26 and page number as 2 char (01-15)

How can I automate the whole process so it does it automatically without any thing from me?

My technical background is I learnt MS office packages in school and completed FreeCodeCamp's Responsive Web Design Certification and I am currently doing Automate the Boring Stuff with Python. I am hoping this is "web scraping", not sure how to classify this project.

I just have a laptop, no server or any cloud accounts. So, I am hoping that I can run it program/script (not sure of the difference) on some free service.

Is Google App Script capable of doing what I want?

Pls mention the steps I need to follow or better if you can like me to a tutorial of anyone doing a project similar to mine.


RE: Download some JPG files and make it a single PDF & share it - Larz60+ - Jul-27-2020

you should learn how to use python requests package: https://requests.readthedocs.io/en/master/
it can be installed with pip install requests
for binary file (which images are) call like:
get_file('myfile url', bytes=True), otherwise get_file('myfile url')

a simple download would be something like:
import requests

def get_file(url, bytes=False):
    response = requests,get(url)
    if response == 200:
        if bytes:
            return response.content
        else:
            return response.text
    else:
        print(f"Bad status code: {response.status_code}"
        return None # This command is ambiguous and may be eliminated. 

        



RE: Download some JPG files and make it a single PDF & share it - rompdeck - Jul-29-2020

(Jul-27-2020, 08:54 PM)Larz60+ Wrote: you should learn how to use python requests package: https://requests.readthedocs.io/en/master/

how do I run it on a server so that I dont have to run it from my laptop?


RE: Download some JPG files and make it a single PDF & share it - Larz60+ - Jul-29-2020

This is just a code snippet that I wrote on the fly.
I expect that you would write additional code around what I suggested here.


RE: Download some JPG files and make it a single PDF & share it - rompdeck - Jul-30-2020

(Jul-29-2020, 09:01 PM)Larz60+ Wrote: This is just a code snippet that I wrote on the fly.
I expect that you would write additional code around what I suggested here.

I want to write my own code. But my question is to run on a server do I have to make it a flask application? I have not written code to run on server, so what do I need to run this code on a server?


RE: Download some JPG files and make it a single PDF & share it - Larz60+ - Jul-31-2020

you will need some way to access from server, flask or some other framework.