UVa Online Jugde Automatic Posting Script


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值