A Chess forum. ChessBanter

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.

Go Back   Home » ChessBanter forum » Chess Newsgroups » rec.games.chess.computer (Computer Chess)
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: , , , , , , , ,

yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn



 
 
Thread Tools Display Modes
  #1  
Old January 17th 06, 09:02 AM posted to rec.games.chess.misc,rec.games.chess.computer,rec.games.chess.analysis
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn

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  
Old January 17th 06, 09:46 AM posted to rec.games.chess.computer
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn

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  
Old January 17th 06, 10:48 AM posted to rec.games.chess.computer
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chessfiles to pgn

* 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  
Old January 17th 06, 11:16 AM posted to rec.games.chess.computer
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn

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  
Old January 17th 06, 12:03 PM posted to rec.games.chess.computer
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn

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  
Old January 17th 06, 12:27 PM posted to rec.games.chess.computer
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn

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  
Old January 17th 06, 04:14 PM posted to rec.games.chess.computer
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn

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  
Old January 17th 06, 11:02 PM posted to rec.games.chess.computer
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chessfiles to pgn

* 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  
Old January 18th 06, 02:30 AM posted to rec.games.chess.misc,rec.games.chess.computer,rec.games.chess.analysis
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn

On 2006-01-17, 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.

Works on SuSE linux. Should work on any GNU linux. Doesn't work on
OSX because of the BSD subsystem's strange 'date'.


Both BSD and GNU date have non-standard extensions.

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

[snip]
ME=`basename $0`


With a POSIX shell such as bash or ksh, this external (i.e., slow)
command is not needed:

ME=${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`


You only need one call to date:

eval "`date -d "$DATEYAHOO" '+DATEPGN=%Y.%m.%d TIMEPGN=+%H:%M:%S'`"

What is the format of the Date string (for that matter of the
entire file)? It can probably be converted without needing an
external command.

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



You only need one call to sed, and grep is not needed:

sed -e 's/;\(Date\):\ \(.*\)/\[\1\ \"'"$DATEPGN"'\"]\
\[Time\ \"'"$TIMEPGN"'\"\]/' $1 \
-e 's/Title/Event/' \
-e 's/;\([^:]*\):\ \(.*\)/\[\1\ \"\2\"]/' \
-e '/^$/d

(I haven't checked your regexps; I trust that they are OK.)

else
print_usage
echo
echo "Error: file $1 does not exist"
fi
--end script--cut above this line--


--
Chris F.A. Johnson http://cfaj.freeshell.org
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
  #10  
Old January 18th 06, 04:02 AM posted to rec.games.chess.misc,rec.games.chess.computer,rec.games.chess.analysis
external usenet poster
 
Posts: n/a
Default yahoo2pgn - a linux shell script for converting Yahoo! Chess files to pgn

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 11:15 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.Content Relevant URLs by vBSEO 2.4.0
Copyright ©2004-2008 ChessBanter, part of the NewsgroupBanter project.
The comments are property of their posters.
Directory - MPAA - eBay - Auto Loans - Loans