Skip to content

Commit

Permalink
Perform merge
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfett committed Apr 9, 2012
2 parents a7b4402 + 3b8483a commit dab99d3
Show file tree
Hide file tree
Showing 214 changed files with 446 additions and 2,061 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@
*.changes
*~
*.egg*
files/dist/
files/build/
files/advancedcaching/build/
/*.zip
freerunner/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions files/advancedcaching/astral.py → advancedcaching/astral.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def solar_noon_utc(self, date, longitude):
newt = self._jday_to_jcentury(julianday + 0.5 + longitude / 360.0)

eqtime = self._eq_of_time(newt)
solarNoonDec = self._sun_declination(newt)
timeUTC = 720.0 + (longitude * 4.0) - eqtime

timeUTC = timeUTC/60.0
Expand Down Expand Up @@ -290,13 +289,11 @@ def solar_azimuth(self, dateandtime, latitude, longitude):
JD = self._julianday(dateandtime.day, dateandtime.month, dateandtime.year)
t = self._jday_to_jcentury(JD + timenow / 24.0)
R = self._sun_rad_vector(t)
alpha = self._sun_rt_ascension(t)
theta = self._sun_declination(t)
Etime = self._eq_of_time(t)

eqtime = Etime
solarDec = theta # in degrees
earthRadVec = R

solarTimeFix = eqtime - (4.0 * longitude) + (60 * zone)
trueSolarTime = dateandtime.hour * 60.0 + dateandtime.minute + dateandtime.second / 60.0 + solarTimeFix
Expand Down Expand Up @@ -365,13 +362,11 @@ def solar_elevation(self, dateandtime, latitude, longitude):
JD = self._julianday(dateandtime.day, dateandtime.month, dateandtime.year)
t = self._jday_to_jcentury(JD + timenow / 24.0)
R = self._sun_rad_vector(t)
alpha = self._sun_rt_ascension(t)
theta = self._sun_declination(t)
Etime = self._eq_of_time(t)

eqtime = Etime
solarDec = theta # in degrees
earthRadVec = R

solarTimeFix = eqtime - (4.0 * longitude) + (60 * zone)
trueSolarTime = dateandtime.hour * 60.0 + dateandtime.minute + dateandtime.second / 60.0 + solarTimeFix
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _get_user_token(self):
page = self.downloader.get_reader('http://www.geocaching.com/map/default.aspx?lat=6&lng=9', login_callback = self.login_callback, check_login_callback = self.check_login_callback)
t = page.read()
user_token[0] = re.search('[A-Z0-9]{128}', t).group(0)
except Exception, e:
except Exception:
raise Exception("Website contents unexpected. Please check connection.")

def _parse_cache_page(self, cache_page, coordinate, num_logs, download_images = True):
Expand Down Expand Up @@ -342,7 +342,7 @@ def basename(url):
except KeyError, e:
raise Exception("Could not find uxLatLon")
except Exception, e:
logger.error("Could not parse this coordinate: %r" % coord_text.text_content())
logger.error("Could not parse this coordinate: %r" % text)
raise e

# Size
Expand Down Expand Up @@ -675,7 +675,6 @@ def _upload_fieldnotes(self, geocaches):

# Upload one or more logs
def _upload_logs(self, geocaches):
notes = []
logger.info("Preparing logs...")
for geocache in geocaches:
if geocache.logdate == '':
Expand Down Expand Up @@ -761,7 +760,7 @@ def _handle_hints(self, hints, encrypted = True):
def _parse_logs_json(self, logs):
try:
r = json.loads(logs)
except Exception, e:
except Exception:
logger.exception('Could not json-parse logs!')
if not 'status' in r or r['status'] != 'success':
logger.error('Could not read logs, status is "%s"' % r['status'])
Expand Down
3 changes: 0 additions & 3 deletions files/advancedcaching/cli.py → advancedcaching/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,6 @@ def perform_update(self):
print "$ No updates available."
self.nt += 1

def show_error(self, message):
print "# Failed: %s" % message

def has_next(self):
# if we have 5 tokens
# then 1..4 are valid tokens (0 is command)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,43 @@
<p style="font-style: normal; font-weight: normal"><font color=
"#000000"><font face="Arial, sans-serif"><font size=
"3"><span style="background: transparent">Es müssen keine Zäune
oder Mauern überwunden werden.</span></font></font></font></p>
oder Mauern überwunden werden.</span></font>
hier steht ein la an ge r Text N49 44.123 E6 34.123 er und das an der</font></font></p>
N 49°
(B-C+A+0,5*D).(F+D)(F-G)(D-2*B)
<p><br />
<br /></p></span>
</div>
<p>
</p>
P J A C Y L T T F R E I T C F G H S E G O N J U E R E N U U<br />
<br />
Den Cache findet ihr dann bei<br />
N 49° 44.(TRRRS) - (S*S)<br />
E 006° 41.RR - S<br />
<br />
Die Berechnung der Finalkoordinaten</i></font></p>
<p style="margin-bottom: 0cm"><font size="4"><i>N 49° 4D.(C+A-E-D)BE</i></font></p>
<p style="margin-bottom: 0cm"><br /></p>
<p style="margin-bottom: 0cm"><font size="4"><i>E 006° 4(E-A+F).(F+E)F(E+B)<br />
<br />
Die Berechnung der Zusatzzahl</i></font></p>
<p style="margin-bottom: 0cm"><br /></p>
<p style="margin-bottom: 0cm"><font size="4"><i>(SxRxNxS)+(PxOxR)-O-P-Q</i></font></p>
<p> </p>
<p><font size="4"><i>Den Final findet Ihr bei</i></font></p>
<p><font size="4"><i>N 49° 4(E+G).H (B+J) (A-E)</i></font></p>
<p><font size="4"><i>E 006° 4(GxB).(F-B) C (H-C)</i></font></p>
<p> </p>
Aufgabe 6:<br />
Cache ist bei N 49° QY.acT, E 006° aC.Kgo<br />
<br />
Aufgabe 6:<br />
Cache ist bei N 49° qy.act, E 006° ac.gg(o+t/2)<br />
Cache ist bei N 49° qy.act, E 006° ac.ab*(b+d)*2<br />
<br />
'''
import geo
import re
Expand Down Expand Up @@ -229,14 +257,18 @@ def __safe_eval(self, text):
def __str__(self):
return "<%s> from %s" % (self.orig, self.source)

SINGLE_CALC_PART = ur'''((?:\([A-Za-z +*/0-9-.,]+\)|[A-Za-z ()+*/0-9-])+)'''
# For aa bb.CCC
SHORT_CALC_PART = ur'''((?:\([A-Za-z +*/0-9-.,]+\)|[A-Za-z ()+*/0-9-]){1,4})'''
# For aa BB.ccc
LONG_CALC_PART = ur'''((?:\([A-Za-z +*/0-9-.,]+\)|[A-Za-z ()+*/0-9-]){1,7})'''

@staticmethod
def find(text, source):
logger.debug("Start parsing...")
text = re.sub(ur'(?u)(°|<[^>]+?>|&[a-zA-Z]{,6};| +|%s|\b[^\W\d_]{4,}\b|\s[^\W\d_]{2,}\s)' % unichr(160), ' ', text)
text = re.sub(ur'(?u)(°|&[a-zA-Z]{,6};|%s)' % unichr(160), ' ', text)
text = re.sub(ur'(?u)( [a-z]{2,}(?= )|<[^>]+?>|\b[^\W\d_]{4,}\b|\s[^\W\d_]{2,}(?=\s))', '|', text)
logger.debug("End Parsing, matching...")
matches = re.findall(ur'''(?<![a-zA-Z])([NSns])\s?([A-Z() -+*/0-9]+?)\s{1,2}%(calc)s[.,\s]%(calc)s['`\s,/]+([EOWeow])\s?([A-Z() -+*/0-9]+?)\s{1,2}%(calc)s[.,\s]%(calc)s[\s'`]*(?![a-zA-Z])''' % {'calc' : CalcCoordinate.SINGLE_CALC_PART}, text)
matches = re.findall(ur'''(?<![a-zA-Z])([NSns])\s?([A-Z() -+*/0-9]{1,5}?)\s{1,2}%(short)s\s?[.,]\s?%(long)s['`\s,/]+([EOWeow])\s?([A-Z() -+*/0-9]{1,5}?)\s{1,2}%(short)s\s?[.,]\s?%(long)s[\s'`]*(?![a-zA-Z])''' % {'short' : CalcCoordinate.SHORT_CALC_PART, 'long' : CalcCoordinate.LONG_CALC_PART}, text)
logger.debug("From source %s with text: '''%s''' I found %d matches" % (source, text, len(matches)))
return [CalcCoordinate(*match, **{'source': source}) for match in matches]

Expand All @@ -249,10 +281,10 @@ def is_calc_string(text):
from simplegui import SimpleGui
print '\n\n========================================================='
h = SimpleGui._strip_html(HTML)
print h
#print h
#for x in h:
# print "%d -> %s" % (ord(x), x)
print '---------------------------------------------------------'
for instance in CalcCoordinate.find(h)[0]:
for instance in CalcCoordinate.find(h, "Example"):
print "Found: %s" % (instance.orig)

5 changes: 3 additions & 2 deletions files/advancedcaching/core.py → advancedcaching/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

from __future__ import with_statement

VERSION = "0.9.0.1"
# This is also evaluated by the build scripts
VERSION='0.9.0.1'
import logging
logging.basicConfig(level=logging.WARNING,
format='%(relativeCreated)6d %(levelname)10s %(name)-20s %(message)s // %(filename)s:%(lineno)s',
Expand Down Expand Up @@ -365,7 +366,7 @@ def try_update(self, silent = False, sync = False):
raise Exception("The update process was stopped while copying files. AGTL may run or not. If not, delete all *.py files in %s." % self.UPDATE_DIR)
finally:
try:
remove(tmpfile)
remove(temp)
except Exception:
pass
except Exception, e:
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
156 changes: 156 additions & 0 deletions advancedcaching/exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2012 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
#

from pyfo import pyfo
import os
from datetime import datetime
from geocaching import GeocacheCoordinate
class Exporter():

def export(self, coordinate, folder = None):
if coordinate.name == '':
raise Exception('Koordinate hat keinen Namen')
if folder == None:
folder = self.path
filename = self.__get_uri(coordinate, folder)
f = open(filename, 'w')
f.write(self.get_text(coordinate))
f.close()

def __get_uri(self, coordinate, folder):
return os.path.join(folder, "%s%s%s" % (coordinate.name, os.extsep, self.EXTENSION))

class GpxExporter(Exporter):

EXTENSION = 'gpx'

def get_text(self, c):
result = pyfo(self.__build_gpx(c), pretty=True, prolog=True, encoding='utf-8')
return result.encode('utf8', 'xmlcharrefreplace')

def __build_gpx(self, c):
return ('gpx',
self.__build_intro(c) + self.__build_main_wp(c) + self.__build_wps(c.get_waypoints()),
{
'xmlns:xsi' : "http://www.w3.org/2001/XMLSchema-instance",
'xmlns:xsd' : 'http://www.w3.org/2001/XMLSchema',
'version' : '1.0',
'creator' : 'AGTL Geocaching Tool',
'xsi:schemaLocation' : "http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0 http://www.groundspeak.com/cache/1/0/cache.xsd",
'xmlns' : "http://www.topografix.com/GPX/1/0"
})

def __build_intro(self, c):
return [
('name', 'AGTL Geocache Listing'),
('desc', ' '),
('email', 'nothing@example.com'),
('url', 'http://www.geocaching.com'),
('urlname', 'Geocaching - High Tech Treasure Hunting'),
('time', '2010-02-27T18:31:24.4812526Z'),
('keywords', 'cache, geocache'),
('author', c.owner),
('bounds', None, c.get_bounds()),

]

def __build_main_wp(self, c):
# prepare some variables...
available = archived = 'True'
if c.status & GeocacheCoordinate.STATUS_DISABLED:
available = 'False'
if not (c.status & GeocacheCoordinate.STATUS_ARCHIVED):
archived = 'False'

return [('wpt',
[
('time', '2010-02-27T18:31:24.4812526Z'),
('name', c.name),
('desc', "%s D%s T%s: %s" % (c.type, c.get_difficulty(), c.get_terrain(), c.title)),
('url', 'http://coord.info/%s' % c.name),
('urlname', c.name),
('sym', 'Geocache'),
('type', 'Geocache|%s' % c.get_gs_type()),
('groundspeak:cache', self.__build_cache_info(c), {
'id' : 42,
'available' : available,
'archived' : archived,
'xmlns:groundspeak' : "http://www.groundspeak.com/cache/1/0"
})
],
{
'lat' : "%.5f" % c.lat,
'lon' : "%.5f" % c.lon
})
]

def __build_cache_info(self, c):
if c.size == 0 or c.size == 5:
cs = 'Not Chosen'
elif c.size == 1:
cs = 'Micro'
elif c.size == 2:
cs = 'Small'
elif c.size == 3:
cs = 'Regular'
elif c.size == 4:
cs = 'Large'
else:
cs = 'Not Chosen'

return [
('groundspeak:name', c.title),
('groundspeak:placed_by', c.owner),
('groundspeak:owner', c.owner, {'id' : '42'}),
('groundspeak:type', c.get_gs_type()),
('groundspeak:container', cs),
('groundspeak:difficulty', c.get_difficulty()),
('groundspeak:terrain', c.get_terrain()),
('groundspeak:country', 'unknown'),
('groundspeak:state', 'unknown'),
('groundspeak:short_description', c.shortdesc, {'html' : 'True'}),
('groundspeak:long_description', c.desc, {'html' : 'True'}),
('groundspeak:encoded_hints', c.hints),
]

def __build_wps(self, wps):
out = []
for wp in wps:
if wp['lat'] == -1 and wp['lon'] == -1:
continue
out += [('wpt',
[
('time', datetime.now().strftime('%Y-%m%dT%H:%M:%S.00')),
('name', wp['id']),
('desc', wp['name']),
('cmt', wp['comment']),
('url', ''),
('urlname', ''),
('sym', 'Trailhead'),
('type', 'Waypoint|Trailhead')
],
{
'lat' : "%.5f" % wp['lat'],
'lon' : "%.5f" % wp['lon']
})
]
return out
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def set_images(self, imgs):
pass

def was_downloaded(self):
return (self.shortdesc != '' or self.desc != '')
return (self.logs != None and self.logs != '')

def get_bounds(self):
minlat = maxlat = self.lat
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit dab99d3

Please sign in to comment.