/usr/share/pyshared/advancedcaching/fieldnotesuploader.py is in agtl 0.8.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2010 Daniel Fett
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
# Author: Daniel Fett agtl@danielfett.de
# Jabber: fett.daniel@jaber.ccc.de
# Bugtracker and GIT Repository: http://github.com/webhamster/advancedcaching
#
VERSION = 3
VERSION_DATE = '2010-07-03'
import geocaching
import re
import gobject
import logging
logger = logging.getLogger('fieldnotesuploader')
class FieldnotesUploader(gobject.GObject):
__gsignals__ = { 'finished-uploading': (gobject.SIGNAL_RUN_FIRST,\
gobject.TYPE_NONE,\
()),
'upload-error' : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
}
#lock = threading.Lock()
URL = 'http://www.geocaching.com/my/uploadfieldnotes.aspx'
def __init__(self, downloader):
gobject.GObject.__init__(self)
self.downloader = downloader
self.notes = []
def add_fieldnote(self, geocache):
if geocache.logdate == '':
raise Exception("Illegal Date.")
if geocache.logas == geocaching.GeocacheCoordinate.LOG_AS_FOUND:
log = "Found it"
elif geocache.logas == geocaching.GeocacheCoordinate.LOG_AS_NOTFOUND:
log = "Didn't find it"
elif geocache.logas == geocaching.GeocacheCoordinate.LOG_AS_NOTE:
log = "Write note"
else:
raise Exception("Illegal status: %s" % geocache.logas)
text = geocache.fieldnotes.replace('"', "'")
self.notes.append('%s,%sT10:00Z,%s,"%s"' % (geocache.name, geocache.logdate, log, text))
def upload(self):
try:
logger.info("Uploading fieldnotes...")
page = self.downloader.get_reader(self.URL).read()
m = re.search('<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="([^"]+)" />', page)
if m == None:
raise Exception("Could not download fieldnotes page.")
viewstate = m.group(1)
text = "\r\n".join(self.notes).encode("UTF-16")
response = self.downloader.get_reader(self.URL,
data=self.downloader.encode_multipart_formdata(
[('ctl00$ContentBody$btnUpload', 'Upload Field Note'), ('ctl00$ContentBody$chkSuppressDate', ''), ('__VIEWSTATE', viewstate)],
[('ctl00$ContentBody$FieldNoteLoader', 'geocache_visits.txt', text)]
))
res = response.read()
if not "successfully uploaded" in res:
raise Exception("Something went wrong while uploading the field notes.")
else:
self.emit('finished-uploading')
logger.info("Finished upload")
except Exception, e:
self.emit('upload-error', e)
|