Author Topic: How difficult is this script to write in Python?  (Read 1226 times)

Archipelago

  • Pencil Stache
  • ****
  • Posts: 781
  • Age: 29
  • Location: NH
How difficult is this script to write in Python?
« on: January 02, 2020, 09:36:02 PM »
Hello,

I’m just learning Python but am curious in starting business applications for it right away. For my job I run a bunch of daily auditing reports and I’d like to automate them. Here is what I want to do:

1. Download data in Excel (.csv) from company website
2. Paste into another Excel file which contains the report
3. Create a PDF printout of report
4. Attach both the Excel file and PDF to an email, then send to a group of people every 2 hours.

Any insight? Thanks in advance!

the_gastropod

  • Bristles
  • ***
  • Posts: 470
  • Age: 37
  • Location: RVA
Re: How difficult is this script to write in Python?
« Reply #1 on: January 02, 2020, 10:05:09 PM »
Python may not be your best option for something like this, since it sounds like you're primarily trying to automate tasks in Excel. I don't have any experience with Windows programming, but I *think* Visual Basic is the tool for this job.

If you're more interested in doing this for educational purposes, Python does have some libraries for dealing with Excel spreadsheets. Check out https://openpyxl.readthedocs.io/en/stable/ But understand, by using Python to do this, you're only able to read/write excel files. You're not interacting with the Excel program itself, so printing / exporting as a PDF / etc. aren't really feasible. For that, Excel's macros (written with Visual Basic) are your best bet.

maizefolk

  • Walrus Stache
  • *******
  • Posts: 7435
Re: How difficult is this script to write in Python?
« Reply #2 on: January 02, 2020, 10:34:26 PM »
Anywhere from really easy to surprisingly hard.

1) Is the csv file posted with the same or predictable names in the same or a predictable URL path? If so easy. If not, less so.
2) If the second excel file also in CSV format? If so easy, if not, hard.
3) Hard to say what you're looking for here. Depending on the format of the report, I'd be tempted to have python write a LaTeX file and then compile that to a PDF.
4) There are some pretty nice python e-mail APIs. Depending on the e-mail service you use, you may have to mess around a bit to get newer security practices to work. The one time I did some automated e-mailing through my gmail account I gave up and just turned off a lot of the improved security features so it'd be easy for my python script to access my inbox.*

*Very geeky and non-practical project. Had a python cron job that checked e-mail, looking for unread messages, and if there was an unread message from anyone on a short list of people I really enjoyed talking to, talked to the hue API and turned a light in my office purple.

habanero

  • Handlebar Stache
  • *****
  • Posts: 1145
Re: How difficult is this script to write in Python?
« Reply #3 on: January 03, 2020, 12:34:10 AM »
Quote
1. Download data in Excel (.csv) from company website
2. Paste into another Excel file which contains the report
3. Create a PDF printout of report
4. Attach both the Excel file and PDF to an email, then send to a group of people every 2 hours.

Its probably not too bad if the data is in a stable standard format etc. As noted depending on how much you need to interact with Excel itself Python might not be the best tool for the job.

1) This should be easy in Python and Python is a good tool for the job. There are a few libraries for downloading files, like Urrlib for example. For scraping web content and getting info out of HTML pages the library BeautifulSoup is your best friend.

2) If its a simple paste operation it should be easy enough using one of the libraries for working with Excel files in Python. But what happens after you paste in the data? Do you need Excel to do a lot of stuff with the newly arrived data? I assume Excel is gonna do some calculations and as far as I know you need to actually open Excel to do this.

3) Dont know. Never worked with pdf files in Python but there is probably a Python library for creating pdf files from Excel.

4) Should be easy to do in Python.