Skip to content

Commit

Permalink
Switch to python & json
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadym Livertovsky committed Nov 21, 2014
1 parent 554cb94 commit 6f19db0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 35 deletions.
19 changes: 13 additions & 6 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ Conky Widget for Godville
About
-----

This widget provides a Godville game client (read only) for Linux Conky. It is based on the [script](http://godville.net/forums/show_topic/257) by [lol2Fast4U](http://godville.net/gods/lol2Fast4U).
This widget provides a Godville game client (read only) for Linux Conky. It is based on the [script](http://godville.net/forums/show_topic/257) by [lol2Fast4U](http://godville.net/gods/lol2Fast4U) but with switching to python parser 100% of the code has been rewritten.
Changes:
- updated to use json (as recommended by Godville Admins)
- updated to be compartible with new Conky versions
- added Conky Manager support
- added long strings split (by words)
- written in python
- inventory count bug corrected
- some logic improvements made
- etc

Installing
----------
Expand All @@ -17,18 +22,20 @@ First you need to allow API requests on your [godville settings page](http://god

####If you are using git and Conky Manager (recommended):

just place all the files to the folder under your conky manager folder, make shure you've allowed executing of `godville.sh` - and here you go! You can activate it in Conky Manager. You can do it with simple cloning the repo:
just place all the files to the folder under your conky manager folder, make sure you've allowed executing of `godville.py` - and here you go!

You can do it with simple cloning the repo:

cd ~/.conky && git clone git@github.com:zesaver/conky_godville.git

Now you can activate it in Conky Manager.

####If you are not using Conky Manager (not tested yet):

just place all the files to any folder you like, make shure you've allowed executing of `godville.sh` and add to your `conkyrc` following:
just place all the files to any folder you like, make sure you've allowed executing of `godville.py` and add to your `~/.conkyrc` following:

${execi 15 /path/to/godville.sh | fold -s -w 50}
${execi 15 /path/to/godville.py | fold -s -w 50}

####P.S.
You may need to install `xsltproc` (`sudo apt-get install xsltproc`) to be able to parse xml answer from the server. Switching to json and some "unix-native" parser is planned in future but not realized yet.

Miscellaneous
-------------
Expand Down
2 changes: 1 addition & 1 deletion godville
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ color1 77B753

minimum_size 300 300
TEXT
${color1}${execi 15 ~/.conky/Godville/godville.sh | fold -s -w 50}
${color1}${execi 15 ./godville.py | fold -s -w 50}



Expand Down
26 changes: 22 additions & 4 deletions godville.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import json

username='YOURNAME'
username = 'ZESAVER'

json_data=requests.get("http://godville.net/gods/api/"+username+".json")
resp = requests.get("http://godville.net/gods/api/"+username+".json")
data = resp.json()

print(data)
print "Героиня: " if data["gender"] == "female" else "Герой: ",(data["name"].encode('utf-8'))
print 'Клан:',data["clan"]
print 'Характер:',data["alignment"].encode('utf-8')
print 'Девиз:',data["motto"].encode('utf-8')
print "Уровень: %.0f (%.0f/100)" % (data["level"],data["exp_progress"])
print "Здоровье: %.0f/%.0f" % (data["health"],data["max_health"])
print "Прана: %.0f/100" % (data["godpower"])
print 'Золотых:',data["gold_approx"].encode('utf-8')
print "Кирпичей: %.0f/100" % (data["bricks_cnt"])
print 'Задание:',data["quest"].encode('utf-8'),"(%.0f/100)" % (data["quest_progress"])
print 'Последняя запись:',data["diary_last"].encode('utf-8')
print "Инвентарь: %.0f/%.0f" % (data["inventory_num"],data["inventory_max_num"])

inventory={}
for n, v in data["inventory"].iteritems():
inventory[v["pos"]] = " %s %s" % (v['pos']+1, n.encode('utf-8'))

print "\n".join([inventory[i] for i in sorted(inventory.keys())])
4 changes: 0 additions & 4 deletions godville.sh

This file was deleted.

20 changes: 0 additions & 20 deletions godville.xslt

This file was deleted.

0 comments on commit 6f19db0

Please sign in to comment.