• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: parsing online data ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parsing online data ?


  • Subject: Re: parsing online data ?
  • From: Shane Stanley <email@hidden>
  • Date: Wed, 14 Mar 2018 12:57:20 +1100

On 13 Mar 2018, at 11:24 pm, Jean-Christophe Helary
<email@hidden> wrote:
>
> Basically I have a version number that compute from the creation date of the
> application that's on the disk, and I want to compare that to the latest
> release data that is somewhere on a web page.
>
> Just so that you see, here is the data:
> https://sourceforge.net/projects/omegat/files/OmegaT - Standard/
> <https://sourceforge.net/projects/omegat/files/OmegaT - Standard/>
> where I'm looking for "2017-12-2" (which is not as precise as a creation
> date, so I'll have to reconsider how I create my local version number, but
> it's good enough).

But if you look at the html, it says:

                    <td headers="files_date_h" class="opt"><abbr
title="2017-12-27 22:56:54 UTC">2017-12-27</abbr></td>

So it looks like a more accurate timestamp is available. So you can do
something like this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

-- load page
set pageURL to current application's |NSURL|'s
URLWithString:"https://sourceforge.net/projects/omegat/files/OmegaT - Standard/";
set {pageHTML, theError} to current application's NSData's
dataWithContentsOfURL:pageURL options:0 |error|:(reference)
if pageHTML = missing value then error (theError's localizedDescription() as
text)
-- make XML
set {theXMLDoc, theError} to current application's NSXMLDocument's alloc()'s
initWithData:pageHTML options:(current application's NSXMLDocumentTidyHTML)
|error|:(reference)
if theXMLDoc = missing value then error (theError's localizedDescription() as
text)
-- parse for file dates
set {theDates, theError} to (theXMLDoc's nodesForXPath:"//td[@headers =
'files_date_h']/abbr//attribute::title" |error|:(reference))
if theDates = missing value then error (theError's localizedDescription() as
text)
return (theDates's valueForKey:"stringValue") as list -- dates for all builds
listed


> I also have a similar page for the "latest" version, and a cloudbees page
> with a slightly different structure for the repository trunk.
> https://omegat.ci.cloudbees.com/job/omegat-trunk/lastBuild/
> <https://omegat.ci.cloudbees.com/job/omegat-trunk/lastBuild/>
That lists much later builds. But it's just a matter of using a different XPath
query.
>
> The issue I see is that if the version is checked each time the script is
> launched (which can be many times a day), the version checking must be fast
> (supposing I'm online, of course), and I don't want a browser to open just
> for that task.

The main issue is the time taken to download the info, which is going to vary
(and is essentially tool agnostic). But the rest should be reasonably snappy.

--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: parsing online data ?
      • From: Jean-Christophe Helary <email@hidden>
References: 
 >parsing online data ? (From: Jean-Christophe Helary <email@hidden>)
 >Re: parsing online data ? (From: Shane Stanley <email@hidden>)
 >Re: parsing online data ? (From: Jim Underwood <email@hidden>)
 >Re: parsing online data ? (From: Shane Stanley <email@hidden>)
 >Re: parsing online data ? (From: Jim Underwood <email@hidden>)
 >Re: parsing online data ? (From: Shane Stanley <email@hidden>)
 >Re: parsing online data ? (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Re: parsing online data ?
  • Next by Date: Re: parsing online data ?
  • Previous by thread: Re: parsing online data ?
  • Next by thread: Re: parsing online data ?
  • Index(es):
    • Date
    • Thread