This repository has been archived on 2018-06-04. You can view files and clone it, but cannot push or open issues/pull-requests.
iMoodUpdater/python/imoodupdater.py

96 lines
3.1 KiB
Python

"""
iMood Updater 1.52-python - Updates your internet mood (imood.com).
Copyright (C) 2003 RiSC, and SDF1 Networks
--------------------------------------------------------------------------
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
GNU License @ http://www.gnu.org/copyleft/gpl.htm
iMood Updater version 1.52-python, Copyright (C) 2003 RiSC, and SDF1 Networks
iMood Updater comes with ABSOLUTELY NO WARRANTY
--------------------------------------------------------------------------
Requirements:
Python 2.2+ (python.org)
PyXML (PyXML.sf.net)
- Only if using source version
--------------------------------------------------------------------------
"""
from xml.dom.ext.reader import Sax2
from whrandom import choice
import httplib, urllib, sys, getopt, crypt, random, re, string
def GenRandStr(length=8, chars=string.uppercase + string.lowercase + string.digits + "./"):
return ''.join([choice(chars) for i in range(length)])
def updateMood(userID, passwd, mood, face, pMood):
params = "email=" + userID + "&crypt=1" + "&password=" + passwd + "&base=" + mood + "&face=" + face + "&personal=" + pMood
print params
try:
tempURL = "/update.cgi" + "?" + params
h = httplib.HTTP("xml.imood.org")
h.putrequest('GET', tempURL)
h.putheader('User-Agent', 'iMood Updater(python)')
h.putheader('Connection', 'close')
h.putheader('Host', 'xml.imood.org')
h.endheaders()
except Exception, reason:
print "Error: Could not contact imood.com"
sys.exit(2)
try:
reply, msg, hdrs = h.getreply()
data = h.getfile().read()
reader = Sax2.Reader()
doc_node = reader.fromString(data)
result = doc_node.documentElement.getElementsByTagName("error")[ 0]
print result.firstChild.data
except Exception, reason:
print "Warning: Bad data from imood.com, mood may not have been updated"
sys.exit(2)
usage = "Usage: %s <account> <password> <\"mood\"> <faceID (0-32)> [\"personal mood\"]\n<> are required params, [] are optional" % sys.argv[0]
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
except getopt.error, msg:
print msg
print "for help use --help"
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
print usage;
sys.exit(0)
try:
userID = sys.argv[1]
salt = GenRandStr()
passwd= crypt.crypt(sys.argv[2], salt)
mood = sys.argv[3]
face = sys.argv[4]
except IndexError:
print usage;
sys.exit(0)
try:
pMood = sys.argv[5]
except IndexError:
pMood = ""
print "Updateing your iMood..."
updateMood(userID, passwd, mood, face, pMood)