![]() |
| If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|||||||
| Tags: chess, converting, files, linux, pgn, script, shell, yahoo, yahoo2pgn |
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I started playing Yahoo! Chess because it's easy to get a game started
in my timezone. I like to let Fritz analyze my games, but the Yahoo! Chess file format cannot be read by ChessBase programs. So I wrote this little shell script to do it for me. Works on SuSE linux. Should work on any GNU linux. Doesn't work on OSX because of the BSD subsystem's strange 'date'. Please pass this along or tweak it or rewrite it in perl or ruby or something. Thanks, -eric --begin script--cut below this line-- #!/bin/sh # # converts chess files from yahoo format to pgn format # Copyright (C) 2006 Eric Sherman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # http://www.gnu.org/copyleft/gpl.html ME=`basename $0` print_usage() { echo "$ME converts chess files from yahoo format to pgn format"; echo "Usage: $ME inFile outFile"; echo "Example: $ME game.yahoo game.pgn"; return } # not enough arguments if [ $# -lt 2 ] ; then print_usage exit 1 fi # file exists? if [ -e $1 ] ; then # convert yahoo date to pgn date/time according to local timezone DATEYAHOO=`grep Date $1 | sed 's/;\([^:]*\):\ \(.*\)/\2/'` DATEPGN=`date -d "$DATEYAHOO" +%Y.%m.%d` TIMEPGN=`date -d "$DATEYAHOO" +%H:%M:%S` sed 's/;\(Date\):\ \(.*\)/\[\1\ \"'"$DATEPGN"'\"]\ \[Time\ \"'"$TIMEPGN"'\"\]/' $1 | # rename Title to Event sed 's/Title/Event/' | # convert yahoo tags to pgn tags sed 's/;\([^:]*\):\ \(.*\)/\[\1\ \"\2\"]/' | # eliminate blank lines grep '.' $2 else print_usage echo echo "Error: file $1 does not exist" fi --end script--cut above this line-- |
| Ads |
|
#2
|
|||
|
|||
|
wrote:
I started playing Yahoo! Chess because it's easy to get a game started in my timezone. :-( I like to let Fritz analyze my games, but the Yahoo! Chess file format cannot be read by ChessBase programs. So I wrote this little shell script to do it for me. Be aware that this script will overwrite an existing .pgn file rather than append to it. Works on SuSE linux. Should work on any GNU linux. As I recall, it won't work on any system where sh isn't linked to bash as pure sh doesn't have functions. Dave. -- David Richerby Portable Beefy Composer (TM): it's www.chiark.greenend.org.uk/~davidr/ like a pupil of Beethoven that's made from a cow but you can take it anywhere! |
|
#3
|
|||
|
|||
|
* David Richerby (10:46) schrieb:
As I recall, it won't work on any system where sh isn't linked to bash as pure sh doesn't have functions. What is pure sh? I have no POSIX to cite, but my /bin/ash surely supports functions, and almost all system scripts depend on that. mfg, simon .... l |
|
#4
|
|||
|
|||
|
On 2006-01-17, Simon Krahnke wrote:
What is pure sh? I have no POSIX to cite, but my /bin/ash surely supports functions, and almost all system scripts depend on that. The original Bourne Shell is not POSIX compatible, is it? AFAIK it does not have functions but I have not checked. -- Ari Makela late autumn - a single chair waiting http://arska.org/hauva/ for someone yet to come -- Arima Akito |
|
#5
|
|||
|
|||
|
In article ,
David Richerby wrote: As I recall, it won't work on any system where sh isn't linked to bash as pure sh doesn't have functions. Depends how pure! The original V7 Bourne shell did not have functions; I don't now recall the exact history, but my copy of the V7 sources has an "orig.sh" and a "sh" dating from 1983 which *does* have functions. That should be far enough back for it to have spread by now .... When in 1993 or so I got a system in which "sh" *was* linked to "bash", the performance was so appalling I that threw it away and compiled up the old sources; the resulting binary was about 20% of the size, much faster, and happily ran all the scripts thrown at it. -- Andy Walker, School of MathSci., Univ. of Nott'm, UK. |
|
#6
|
|||
|
|||
|
Ari Makela wrote:
Simon Krahnke wrote: What is pure sh? I have no POSIX to cite, but my /bin/ash surely supports functions, and almost all system scripts depend on that. The original Bourne Shell is not POSIX compatible, is it? AFAIK it does not have functions but I have not checked. By ``pure sh'', I meant the original Bourne shell, yes. It isn't POSIX- compliant because it predates POSIX by quite some time. I'm fairly sure it doesn't have functions. In this day and age, sh is usually a symlink to bash or something like it, which does support functions. But one should #!/bin/bash if using the features of that particular shell. Dave. -- David Richerby Erotic Generic Painting (TM): it's www.chiark.greenend.org.uk/~davidr/ like a Renaissance masterpiece but it's just like all the others and genuinely erotic! |
|
#7
|
|||
|
|||
|
I should have qualified my original post with "It works for me. Your
mileage may vary." And I hadn't thought of appending to the pgn file since I kind of hate it when that is the default behavior. My workflow involves throwing the pgn file away--the game gets added to my MyInternetGames chessbase after Fritz's analysis. -eric |
|
#8
|
|||
|
|||
|
* David Richerby (13:27) schrieb:
By ``pure sh'', I meant the original Bourne shell, yes. It isn't POSIX- compliant because it predates POSIX by quite some time. I'm fairly sure it doesn't have functions. I'm fairly sure no one's using the original Bourne shell in 2006. In this day and age, sh is usually a symlink to bash or something like it, which does support functions. But one should #!/bin/bash if using the features of that particular shell. Yes, but functions are not features of a particular shell but of any modern shell that is likely to be linked to /bin/sh. mfg, simon .... l |
|
#9
|
|||
|
|||
|
|
|
#10
|
|||
|
|||
|
I'm usually content to simply get these kinds of quick-and-dirty
scripts to work and then forget them. Thank you very much for your script-fu. The date format that yahoo produces just happens to be exactly the default output format of GNU's date -- "Tue Jan 17 20:59:41 MST 2006". (Fritz9 just arrived in the mail, yay.) -eric |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| rec.games.chess.misc FAQ [2/4] | pribut@yahoo.com | rec.games.chess.misc (Chess General) | 0 | January 3rd 06 06:04 AM |
| rec.games.chess.misc FAQ [2/4] | pribut@yahoo.com | rec.games.chess.misc (Chess General) | 0 | December 19th 05 05:36 AM |
| rec.games.chess.misc FAQ [2/4] | pribut@yahoo.com | rec.games.chess.misc (Chess General) | 0 | December 4th 05 05:29 AM |
| rec.games.chess.misc FAQ [2/4] | pribut@yahoo.com | rec.games.chess.misc (Chess General) | 0 | November 3rd 05 05:30 AM |
| rec.games.chess.misc FAQ [2/4] | pribut@yahoo.com | rec.games.chess.misc (Chess General) | 0 | October 19th 05 05:37 AM |