Skip to content
This repository has been archived by the owner on Jun 21, 2021. It is now read-only.

Moving to python3 #78

Merged
merged 2 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions data/geodata.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-

from __future__ import print_function


from collections import namedtuple
from datetime import datetime
from decimal import Decimal
from urlparse import urljoin
from urllib.parse import urljoin
import os
import sys
import time
Expand All @@ -27,7 +27,7 @@
db,
)

unicodecsv.field_size_limit(sys.maxint)
unicodecsv.field_size_limit(sys.maxsize)


CountryInfoRecord = namedtuple(
Expand Down Expand Up @@ -237,7 +237,7 @@ def load_geonames(fd):

for counter, line in enumerate(fd):
loadprogress.update(counter)
line = unicode(line, 'utf-8')
line = str(line, 'utf-8')

if not line.startswith('#'):
rec = GeoNameRecord(*line.strip().split('\t'))
Expand Down Expand Up @@ -285,9 +285,9 @@ def load_geonames(fd):
gn = GeoName(geonameid=int(item.geonameid))
db.session.add(gn)

gn.title = item.title or u''
gn.ascii_title = item.ascii_title or unidecode(item.title or u'').replace(
u'@', u'a'
gn.title = item.title or ''
gn.ascii_title = item.ascii_title or unidecode(item.title or '').replace(
'@', 'a'
)
gn.latitude = Decimal(item.latitude) or None
gn.longitude = Decimal(item.longitude) or None
Expand Down
118 changes: 59 additions & 59 deletions data/networkbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,108 +8,108 @@
db.session.add_all(
[
NetworkLink(
seq=1, name=u'home', title=u'HasGeek', url=u'http://hasgeek.com/'
seq=1, name='home', title='HasGeek', url='http://hasgeek.com/'
),
NetworkLink(
seq=2, name=u'blog', title=u'Blog', url=u'http://blog.hasgeek.com/'
seq=2, name='blog', title='Blog', url='http://blog.hasgeek.com/'
),
NetworkLink(
seq=3, name=u'jobs', title=u'Jobs', url=u'http://jobs.hasgeek.com/'
seq=3, name='jobs', title='Jobs', url='http://jobs.hasgeek.com/'
),
NetworkLink(seq=4, name=u'hgtv', title=u'TV', url=u'http://hasgeek.tv/'),
NetworkLink(seq=4, name='hgtv', title='TV', url='http://hasgeek.tv/'),
NetworkLink(
seq=5,
name=u'funnel',
title=u'Funnel',
url=u'http://funnel.hasgeek.com/',
name='funnel',
title='Funnel',
url='http://funnel.hasgeek.com/',
),
NetworkLink(
seq=6, name=u'geekup', title=u'Geekup', url=u'http://geekup.in/'
seq=6, name='geekup', title='Geekup', url='http://geekup.in/'
),
NetworkLink(
seq=7,
name=u'hacknight',
title=u'Hacknight',
url=u'http://hacknight.in/',
name='hacknight',
title='Hacknight',
url='http://hacknight.in/',
),
]
)

events = NetworkLink(seq=8, name=u'events', title=u'Events')
workshops = NetworkLink(seq=9, name=u'workshops', title=u'Workshops')
events = NetworkLink(seq=8, name='events', title='Events')
workshops = NetworkLink(seq=9, name='workshops', title='Workshops')
db.session.add_all([events, workshops])

db.session.add_all(
[
NetworkLink(
seq=20,
parent=events,
name=u'fifthelephant',
title=u'The Fifth Elephant',
url=u'http://fifthelephant.in/',
name='fifthelephant',
title='The Fifth Elephant',
url='http://fifthelephant.in/',
),
NetworkLink(
seq=21,
parent=events,
name=u'pastevents',
title=u'Past events',
name='pastevents',
title='Past events',
sep=True,
),
NetworkLink(
seq=22,
parent=events,
name=u'metarefresh',
title=u'Meta Refresh',
url=u'http://metarefresh.in/',
name='metarefresh',
title='Meta Refresh',
url='http://metarefresh.in/',
),
NetworkLink(
seq=23,
parent=events,
name=u'jsfoo',
title=u'JSFoo',
url=u'http://jsfoo.in/',
name='jsfoo',
title='JSFoo',
url='http://jsfoo.in/',
),
NetworkLink(
seq=24,
parent=events,
name=u'droidcon',
title=u'Droidcon',
url=u'http://droidcon.in/',
name='droidcon',
title='Droidcon',
url='http://droidcon.in/',
),
NetworkLink(
seq=25,
parent=events,
name=u'cartonama',
title=u'Cartonama Conference',
url=u'http://cartonama.com/2012',
name='cartonama',
title='Cartonama Conference',
url='http://cartonama.com/2012',
),
NetworkLink(
seq=26,
parent=events,
name=u'rootconf',
title=u'Rootconf',
url=u'http://rootconf.in/',
name='rootconf',
title='Rootconf',
url='http://rootconf.in/',
),
NetworkLink(
seq=27,
parent=events,
name=u'phpcloud',
title=u'Scaling PHP in the Cloud',
url=u'http://phpcloud.hasgeek.com/',
name='phpcloud',
title='Scaling PHP in the Cloud',
url='http://phpcloud.hasgeek.com/',
),
NetworkLink(
seq=28,
parent=events,
name=u'androidcamp',
title=u'AndroidCamp',
url=u'http://androidcamp.hasgeek.com/',
name='androidcamp',
title='AndroidCamp',
url='http://androidcamp.hasgeek.com/',
),
NetworkLink(
seq=29,
parent=events,
name=u'doctypehtml5',
title=u'DocType HTML5',
url=u'http://www.doctypehtml5.in/',
name='doctypehtml5',
title='DocType HTML5',
url='http://www.doctypehtml5.in/',
),
]
)
Expand All @@ -118,44 +118,44 @@
NetworkLink(
seq=50,
parent=workshops,
name=u'advancedpython',
title=u'Advanced Python',
url=u'http://advancedpython.hasgeek.com/',
name='advancedpython',
title='Advanced Python',
url='http://advancedpython.hasgeek.com/',
),
NetworkLink(
seq=51,
parent=workshops,
name=u'pastworkshops',
title=u'Past workshops',
name='pastworkshops',
title='Past workshops',
sep=True,
),
NetworkLink(
seq=52,
parent=workshops,
name=u'gitworkshop',
title=u'Git Workshop',
url=u'http://gitworkshop.hasgeek.com/',
name='gitworkshop',
title='Git Workshop',
url='http://gitworkshop.hasgeek.com/',
),
NetworkLink(
seq=53,
parent=workshops,
name=u'pigworkshop',
title=u'Pig Workshop',
url=u'http://pigworkshop.fifthelephant.in/',
name='pigworkshop',
title='Pig Workshop',
url='http://pigworkshop.fifthelephant.in/',
),
NetworkLink(
seq=54,
parent=workshops,
name=u'cssforthesoul',
title=u'CSS for the Soul',
url=u'http://cssworkshop.metarefresh.in/',
name='cssforthesoul',
title='CSS for the Soul',
url='http://cssworkshop.metarefresh.in/',
),
NetworkLink(
seq=55,
parent=workshops,
name=u'cartonamaworkshop',
title=u'Cartonama Workshop',
url=u'http://workshop.cartonama.com/',
name='cartonamaworkshop',
title='Cartonama Workshop',
url='http://workshop.cartonama.com/',
),
]
)
Expand Down
44 changes: 22 additions & 22 deletions hascore/models/geoname.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@

def filtlike(q):
return (
q.replace(u'%', ur'\%')
.replace(u'_', ur'\_')
.replace(u'[', u'')
.replace(u']', u'')
+ u'%'
q.replace('%', r'\%')
.replace('_', r'\_')
.replace('[', '')
.replace(']', '')
+ '%'
)


Expand Down Expand Up @@ -182,7 +182,7 @@ def picker_title(self):
state = None
suffix = None

if (self.fclass, self.fcode) == (u'L', u'CONT'):
if (self.fclass, self.fcode) == ('L', 'CONT'):
suffix = 'continent'
country = None
state = None
Expand Down Expand Up @@ -220,17 +220,17 @@ def geoname(self):
@property
def use_title(self):
usetitle = self.ascii_title
if self.fclass == u'A' and self.fcode.startswith(u'PCL'):
if u'of the' in usetitle:
usetitle = usetitle.split(u'of the')[-1].strip()
elif u'of The' in usetitle:
usetitle = usetitle.split(u'of The')[-1].strip()
elif u'of' in usetitle:
usetitle = usetitle.split(u'of')[-1].strip()
elif self.fclass == u'A' and self.fcode == 'ADM1':
if self.fclass == 'A' and self.fcode.startswith('PCL'):
if 'of the' in usetitle:
usetitle = usetitle.split('of the')[-1].strip()
elif 'of The' in usetitle:
usetitle = usetitle.split('of The')[-1].strip()
elif 'of' in usetitle:
usetitle = usetitle.split('of')[-1].strip()
elif self.fclass == 'A' and self.fcode == 'ADM1':
usetitle = (
usetitle.replace(u'State of', '')
.replace(u'Union Territory of', '')
usetitle.replace('State of', '')
.replace('Union Territory of', '')
.strip()
)
return usetitle
Expand All @@ -256,7 +256,7 @@ def checkused(c):
)

with db.session.no_autoflush:
self.name = unicode(
self.name = str(
make_name(usetitle, maxlength=250, checkused=checkused)
)

Expand All @@ -277,7 +277,7 @@ def related_geonames(self):
related['admin1'] = self.admin1code.geoname
if self.country and self.country.geonameid != self.geonameid:
related['country'] = self.country.geoname
if (self.fclass, self.fcode) != (u'L', u'CONT') and self.country:
if (self.fclass, self.fcode) != ('L', 'CONT') and self.country:
related['continent'] = GeoName.query.get(
continent_codes[self.country.continent]
)
Expand All @@ -292,8 +292,8 @@ def as_dict(self, related=True, alternate_titles=True):
'short_title': self.short_title,
'use_title': self.use_title,
'picker_title': self.picker_title,
'latitude': unicode(self.latitude),
'longitude': unicode(self.longitude),
'latitude': str(self.latitude),
'longitude': str(self.longitude),
'fclass': self.fclass,
'fcode': self.fcode,
'country': self.country_id,
Expand All @@ -305,7 +305,7 @@ def as_dict(self, related=True, alternate_titles=True):
'is_country': bool(self.has_country),
'is_admin1': bool(self.has_admin1code),
'is_admin2': bool(self.has_admin2code),
'is_continent': (self.fclass, self.fcode) == (u'L', u'CONT'),
'is_continent': (self.fclass, self.fcode) == ('L', 'CONT'),
'population': self.population,
'elevation': self.elevation,
'dem': self.dem,
Expand All @@ -329,7 +329,7 @@ def get(cls, name):
@classmethod
def get_by_title(cls, titles, lang=None):
results = set()
if isinstance(titles, basestring):
if isinstance(titles, str):
titles = [titles]
for title in titles:
if lang:
Expand Down
2 changes: 1 addition & 1 deletion hascore/models/networkbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NetworkLink(BaseNameMixin, db.Model):
public = db.Column(db.Boolean, default=True, nullable=False)

def __repr__(self):
return u'<NetworkLink {seq} {name} "{title}">'.format(
return '<NetworkLink {seq} {name} "{title}">'.format(
seq=self.seq, name=self.name, title=self.title
)

Expand Down
Loading