How to run an R script in Powershell?

Need script to run on Mac OSX to pull scores from a website

  • I need a an executable script (php, Applescript etc) I can run on OSX to pull scores from the Japan Golf Tour website and returns a text file to BBEdit or just returns a text file to the desktop and saves it to a certain folder. The Japan Golf Tour website can be found at http://www.jgto.org/jgto/WG01000000Init.do Unfortuntely the page for the scores changes each day, however it is always the same link on the front page called "FULL LEADERBOARD". The name of the link is always the same but the actual HTML link changes. So to get to the scores page via any script it will need to read the above page, sift through the source code and go to the URL behind that link. Once on the scores page we need the scores pulled out in the following order: Position Score Player Name (1-2-3-4) And the rest of the columns are rejected. However on day one of the tournament, there will only be a score in the "1" column and there will be dashes in 2, 3 and 4 as those rounds have yet to be played. On day two there will be a score under "1" and "2" column but dashes under 3 and 4 and so on. The script will need some conditional statements to test for this and use the appropriate round numbers eg if there is one score and three dahses, it's obviously day one of the tournament. We then need it to check everyone has finished playing the tournament for the day and the word "FIN" is in the "Hole" column, if that is not there on every line then the script needs to alert the user to this fact and that the tuornament has yet to finish - try again later. If everythign is right (eg all "FIN") then the data is pulled out in the following way: 1 -8 Takao Nogami (64) T2 -6 Akinori Tani (65) T2 -6 David Smail (65) T2 -6 Hideto Tanihara (65) T2 -6 Shingo Katayama (65) 6 -6 Soushi Tajima (66) T7 -5 Brendan Jones (68) T7 -5 Eiji Mizoguchi (68) T7 -5 Hidemasa Hoshino (68) T7 -5 Hirofumi Miyase (68) T7 -5 Prayad Marksaeng (68) T7 -5 Takuya Taniguchi (68) T7 -5 Tateo Jet Ozaki (68) T14 -4 Hiroshi Makino (69) T14 -4 Jong-Duck Kim (69) T14 -4 Keiichiro Fukabori (69) T14 -4 Mitsuo Harada (69) T14 -4 Paul Sheehan (69) T14 -4 Shigeru Nonaka (69) T14 -4 Takeshi Kajikawa (69) T14 -4 Thaworn Wiratchant (69) T14 -4 Toshihiro Aizawa (69) T14 -4 Toshinori Muto (69) T14 -4 Wen-Chong Liang (69) T14 -4 Yoichi Shimizu (69) etc etc.............. The numbers in brackets at the end are the round scores. On day one you get (xx), day two you get (xx-xx) or day three (xx-xx-xx) and so on. We need to fill in the missing position numbers from the table - eg the first column plus need to put a "T" in front of them if there is more than one and ;eave as is if not eg 1st place or 6th place outright in the example above. As well as all that each bunch of players on the same score is sorted by first name ascending for easy reading. The final thing is certain players get highlighted by wrapping them in [b]Player Name[/b]. We would need a place in the script to be able to add in an array of names...manually is fine. So when the script is run and it has done everythign and returned the text the final thing it does is run through the names and wraps the whole line with the matching player name as in the previous sentence. Hope that all makes sense.

  • Answer:

    Dear srv007, I have written a Python script to your specifications. You may download it from the following location. plaintext file: japan_golf.py http://plg.uwaterloo.ca/~mlaszlo/answers/japan_golf.py The Python interpreter is usually preinstalled on OS X. If this is not true in your case, or if you want the latest version of Python, you can install it by following the instructions on the following page. python.org: Python on the Mac http://www.python.org/download/mac/ To run the script, execute python japan_golf.py outfile.txt or just python japan_golf.py from the command line. The parsing results are printed to standard output, and optionally to the file name specified by the second argument, if any. This code should work as long as the Japan Golf Tour website continues to display scores in the same format. Due to the idiosyncratic nature of their HTML output, the code is likely to break if their format changes. Within the first few lines of the script, you will find an array named highlight_names, which you can fill with the players' names you wish to see highlighted. An empty array is written [] and an array of one name is ['Tiger Woods'] while an array of two names looks like ['Tiger Woods', 'Ernie Els'] and so on. It wasn't clear to me from your instructions whether you wanted only the player's name highlighted, or the entire line that contains the player's name. At present, the entire line is enclosed in [b] [/b] tags, but I can easily change it so that only the name is boldfaced. If there are other small changes you would like me to make, or if you have any trouble running the script, please let me know through a Clarification Request and give me a chance to fully meet your needs before you rate this answer. Regards, leapinglizard Search strategy: macintosh python ://www.google.com/search?q=macintosh+python

srv007-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.