Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*pyc
Empty file added __init__.py
Empty file.
38 changes: 24 additions & 14 deletions lighthouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,14 @@ def get_all_tickets(self, project):
c = 30
page = 1
ticket_count = 0
while c == 30:
while c >= 30:
c = self.get_tickets(project, page)
ticket_count += c
page += 1

def get_tickets(self, project, page=1):
"""Retrieves all the tickets in a project
"""Retrieves all the tickets in a page of a project.
If no page is specified, the first is used.

>>> lh = Lighthouse()
>>> lh.url = 'http://ars.lighthouseapp.com'
Expand Down Expand Up @@ -316,22 +317,31 @@ def get_tickets(self, project, page=1):
if(ticket_list.get('children', None)):
for ticket in ticket_list['children']:
c += 1
t_obj = Ticket()
for field in ticket['children']:
field_name, field_value, field_type = \
self._parse_field(field)
py_field_name = field_name.replace('-', '_')
t_obj.__setattr__(py_field_name, field_value)
t_obj.fields.add(py_field_name)
project.tickets[t_obj.number] = t_obj
if( ticket.get('children', None) ): # Got the KeyError 'children', so check whether it exists
t_obj = Ticket()
for field in ticket['children']:
field_name, field_value, field_type = \
self._parse_field(field)
py_field_name = field_name.replace('-', '_')
t_obj.__setattr__(py_field_name, field_value)
t_obj.fields.add(py_field_name)
project.tickets[t_obj.number] = t_obj
return c

def get_new_tickets(self, project):
"""Retrieves all the tickets in the first page of a project,
then returns a list with the new ones.
"""
old_tickets = project.tickets;
self.get_tickets(project)
return list(set(project.tickets).difference(set(old_tickets)))

def get_full_ticket(self, project, ticket):
path = Ticket.endpoint_single % (project.id, ticket.number)
ticket_data = self._get_data(path)

for field in ticket_data['children']:
field_name, field_value, field_type = \
self._parse_field(field)
field_name, field_value, field_type = self._parse_field(field)
py_field_name = field_name.replace('-', '_')
ticket.__setattr__(py_field_name, field_value)
ticket.fields.add(py_field_name)
Expand Down Expand Up @@ -384,7 +394,7 @@ def __init__(self):

def __repr__(self):
if self.title:
return "Ticket: %s" % (self.title,)
return "Ticket: %s" % (self.title.encode('ascii', 'replace'),)
else:
return "Ticket: Unnamed"

Expand Down Expand Up @@ -428,4 +438,4 @@ def __init__(self, arg):

if __name__ == "__main__":
import doctest
doctest.testmod(optionflags=doctest.IGNORE_EXCEPTION_DETAIL)
doctest.testmod(optionflags=doctest.IGNORE_EXCEPTION_DETAIL)