现在的位置: 首页 > 综合 > 正文

UVa Online Jugde Automatic Posting Script

2013年08月09日 ⁄ 综合 ⁄ 共 2353字 ⁄ 字号 评论关闭

I develop a script to post my code to the UVa online judge
automatically. This tool will also replace the local #include's with
its real content when uploading the code to the server. So, I haven't 
to paste the code all around any more.

Curl and Firefox is required to use this script. Firefox stores various information in SQLite databases, thus makes it easy to access it by third-party tools. Your cookies must be passed to the server for validating your login session.

Code:

  1. #!/bin/bash
  2. # ************************************************************************* #
  3. #    Copyright (C) 2008 by Liu Kaipeng                                      # 
  4. #    LiuKaipeng at gmail dot com                                            #
  5. # ************************************************************************* #
  6. source=$1.cpp
  7. if [ ! -e $source ]; then
  8.     echo $source do not exist.
  9.     exit
  10. fi
  11. # replace the local #include's with its file content
  12. post=$1.post
  13. cp $source $post
  14. includes=$(grep '#include ".*"' $post | cut -d/" -f 2)
  15. for f in $includes; do
  16.     sed -i -e '/@#include "'"$f"'"@{
  17.         r '"$f"'
  18.         d
  19.     }' $post
  20. done
  21. problemid="problemid="
  22. category="category="
  23. problem="localid=$1"
  24. language="language=3"
  25. code="code="
  26. codeupl="codeupl=@$post"
  27. refer='http://icpcres.ecs.baylor.edu/onlinejudge/index.php?'/
  28. 'option=com_onlinejudge&Itemid=25'
  29. target='http://icpcres.ecs.baylor.edu/onlinejudge/index.php?'/
  30. 'option=com_onlinejudge&Itemid=25&page=save_submission'
  31. cookiedb=~/.mozilla/firefox/alv3pwo5.default/cookies.sqlite
  32. cookie=$(sqlite3 -line $cookiedb /
  33.     'select name,value from moz_cookies where host glob "*.ecs.baylor.edu";')
  34. cookie=$(echo ${cookie} | sed 's/name = //g;s/ value = /=/g;s/ /;/g')
  35. curl --silent --output submission.html /
  36.     --refer "$refer" /
  37.     --cookie "$cookie" /
  38.     --header "Expect:" /
  39.     --header "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) "/
  40. "Gecko/2008111318 Ubuntu/8.10 (intrepid) Firefox/3.0.4" /
  41.     --header "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" /
  42.     --header "Accept-Language: en-us,en;q=0.5" /
  43.     --header "Accept-Encoding: gzip,deflate" /
  44.     --header "Accept-Charset: UTF-8,*" /
  45.     --header "Keep-Alive: 300" /
  46.     --header "Connection: keep-alive" /
  47.     --location --max-redirs 3 /
  48.     --form-string "$problemid" /
  49.     --form-string "$category" /
  50.     --form-string "$problem" /
  51.     --form-string "$language" /
  52.     --form-string "$code" /
  53.     --form "$codeupl" /
  54.     $target

【上篇】
【下篇】

抱歉!评论已关闭.