TwinyTwice
Posts: 24
Joined: Mon Sep 15, 2014 7:08 am
Location: France

Need help to convert Applescript with Curl in Python script

Tue Sep 23, 2014 3:17 am

Hi everybody,

I'm a newbies in python dev and i need some help for converting an little Applescript that i've created !

This script scans the contents of html page and extracts information and gives me the result with a GUI dialog!

Code: Select all

set startHere to "View content" & return

set blurb0 to (do shell script "curl http://myurl.com | textutil -stdin -stdout -format html -convert txt -encoding UTF-8")
set TID to text item delimiters
set text item delimiters to startHere
set blurb1 to text item 2 of blurb0
set text item delimiters to TID
set blurb2 to paragraph 1 of blurb1

display dialog "Hi, your new content is " & blurb2 & " !!!" buttons {"Sounds Good"} default button "Sounds Good" with title "Raspberry B RT" with icon path to resource "rpi.icns" in bundle (path to me)
Firstly: is it possible to have an equivalent script that could do this in python?

For those who would like to help me, i would change the outcome of the information that is given in the GUI dialog with a message that will be transmitted on a 2x16 LCD (HD44780) screen.

Sorry for Double Ducth language, i'm French !

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Need help to convert Applescript with Curl in Python scr

Tue Sep 23, 2014 11:50 am

The thing I've seen used for HTML scraping is http://www.crummy.com/software/BeautifulSoup/

There's an example here: https://github.com/piface/pifacecad/blo ... intimes.py which displays some data on an LCD screen. That python program is based on https://github.com/seanbechhofer/raspbe ... /trains.py

They're parsing the HTML from http://ojp.nationalrail.co.uk/service/l ... BSK/WAT/To
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

TwinyTwice
Posts: 24
Joined: Mon Sep 15, 2014 7:08 am
Location: France

Re: Need help to convert Applescript with Curl in Python scr

Tue Sep 23, 2014 1:47 pm

Again you ;-) , haha !

Again lot of thanks @DougieLawson.

TwinyTwice
Posts: 24
Joined: Mon Sep 15, 2014 7:08 am
Location: France

Re: Need help to convert Applescript with Curl in Python scr

Wed Sep 24, 2014 4:49 am

For those that might be interested, here's an alternative to BeautifullSoup for parse html :
---> https://github.com/aaronsw/html2text

There also http://lxml.de to parse biggest files !

Return to “Other programming languages”