community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1745881 - in /comdev/nearby_people/nearby: foaf.py views.py
Date Sat, 28 May 2016 14:43:13 GMT
Author: nick
Date: Sat May 28 14:43:13 2016
New Revision: 1745881

URL: http://svn.apache.org/viewvc?rev=1745881&view=rev
Log:
Support for getting a list of FOAF files from a directory

Modified:
    comdev/nearby_people/nearby/foaf.py
    comdev/nearby_people/nearby/views.py

Modified: comdev/nearby_people/nearby/foaf.py
URL: http://svn.apache.org/viewvc/comdev/nearby_people/nearby/foaf.py?rev=1745881&r1=1745880&r2=1745881&view=diff
==============================================================================
--- comdev/nearby_people/nearby/foaf.py (original)
+++ comdev/nearby_people/nearby/foaf.py Sat May 28 14:43:13 2016
@@ -32,10 +32,12 @@ NS_PM = "http://www.web-semantics.org/ns
 NS_DC = "http://purl.org/dc/elements/1.1/"
 
 class FOAF(object):
-    def __init__(self, doap_file):
+    "Handles a list of FOAF files, as defined in a DOAP file"
+    def __init__(self, doap_file, warn_no_location=True):
         self.doap_file = doap_file
         self.people = {}
         self.updated_at = None
+        self.warn_no_location = warn_no_location
 
     def get_nearby(self, lat, long, rows = 10):
         self.ensure_data()
@@ -69,6 +71,14 @@ class FOAF(object):
         if datetime.datetime.utcnow() - self.updated_at > datetime.timedelta(hours=12):
             self._refresh()
 
+    @staticmethod
+    def clean_latlong(ll):
+        # No brackets
+        ll = ll.replace("(","").replace(")","")
+        # No degree symbols
+        ll = ll.replace(u'\N{DEGREE SIGN}',"")
+        return ll
+
     def _refresh(self):
         doap = parse(self.doap_file)
         foaf_people = doap.getElementsByTagNameNS(NS_FOAF,"Person")
@@ -95,7 +105,9 @@ class FOAF(object):
                    usock.close()        
                 except IOError, e:
                    sys.stderr.write("Skipping %s due to broken server: %s\n" % (uri,e))
+        self._mark_updated()
                 
+    def _mark_updated(self):
         self.updated_at = datetime.datetime.utcnow()
         
     def _parse_foaf(self, data, filename):
@@ -165,6 +177,7 @@ class FOAF(object):
                 lat = lat[:-1]
                 if not lat.startswith("-"):
                     lat = "-%s" % lat
+            lat = FOAF.clean_latlong(lat)
         if long:
             if long.endswith("E"):
                 long = long[:-1]
@@ -172,6 +185,7 @@ class FOAF(object):
                 long = long[:-1]
                 if not long.startswith("-"):
                     long = "-%s" % long
+            long = FOAF.clean_latlong(long)
     
         if currentProjectsN:
             for projectN in currentProjectsN:
@@ -187,7 +201,7 @@ class FOAF(object):
                 if documentN:
                     url = documentN[0].getAttribute("rdf:about")
                     dt = documentN[0].getElementsByTagNameNS(NS_DC,"title")
-                    if dt:
+                    if dt and dt[0].firstChild:
                        title = dt[0].firstChild.data
                     else:
                        title = url
@@ -214,4 +228,22 @@ class FOAF(object):
                 "avatar": depiction, "weblogs": weblogs
             }
         else:
-            sys.stderr.write("Skipping %s due to missing %s\n" % (filename,missing))
+            if not self.warn_no_location and \
+                 (set(("lat","long")) <= set(missing) and len(missing) == 2):
+                # Only missing lat and long, but no warning requested
+                pass
+            else:
+                sys.stderr.write("Skipping %s due to missing %s\n" % (filename,missing))
+
+class ListingFOAF(FOAF):
+    "Handles a list of FOAF files, as found in a directory"
+    def __init__(self, directory):
+        super(ListingFOAF,self).__init__(None, False)
+        self.directory = directory
+
+    def _refresh(self):
+        for fn in os.listdir(self.directory):
+            if fn.lower().endswith(".rdf"):
+                file = os.path.join(self.directory, fn)
+                self._parse_foaf(file, fn)
+        self._mark_updated()

Modified: comdev/nearby_people/nearby/views.py
URL: http://svn.apache.org/viewvc/comdev/nearby_people/nearby/views.py?rev=1745881&r1=1745880&r2=1745881&view=diff
==============================================================================
--- comdev/nearby_people/nearby/views.py (original)
+++ comdev/nearby_people/nearby/views.py Sat May 28 14:43:13 2016
@@ -33,6 +33,7 @@ except ImportError:
 
 comdev_foaf = FOAF(COMDEV_DOAP)
 speakers_foaf = FOAF(SPEAKERS_DOAP)
+all_public_foaf = ListingFOAF(PEOPLE_FOAF_PATH)
 
 def welcome(request):
    form = PlaceForm()
@@ -93,7 +94,7 @@ def retrieve_people_data(form):
       foaf = speakers_foaf
       people_type = "Speakers"
    if form.data.get("type",None) == "all":
-      foaf = speakers_foaf # TODO All public
+      foaf = all_public_foaf
       people_type = "Public Committers"
 
    search_data = form.data



Mime
View raw message