Beispiel #1
0
	def cacheData(self):
		r = redis.StrictRedis(host='localhost',port=6379,db=0)
		bc = Basecamp('https://seertechnologies.basecamphq.com', self.api_token)
		i = 1
		userlist = {}

		xml = bc.people().text
		items = ET.fromstring(xml).findall('person')
		for item in items:
			#all users in seer
			r.hset('Users:' + item.find('email-address').text, 'name',item.find('first-name').text + " " + item.find('last-name').text)
			r.hset('Users:' + item.find('email-address').text, 'id',item.find('id').text)
			r.hset('Users:' + item.find('email-address').text, 'email',item.find('email-address').text)

		xml = bc.projects().text
		items = ET.fromstring(xml).findall('project')
		for item in items:
			#all projects under seer
			projectname = item.find('name').text
			projectid = item.find('id').text
			print projectname
			print projectid

			r.hset('Projects:' + projectname,"name",projectname)
			r.hset('Projects:' + projectname,"id",projectid)

			r.zadd('Projects',1,projectname)

			x = 1
			while 1:
				#every time log in a project
				time_entries_data = bc.time_entries_per_project(project_id = int(projectid), page = x)

				if x > int(time_entries_data.headers['X-Pages']):
					break

				time_entries = time_entries_data.text

				items2 = ET.fromstring(time_entries).findall('time-entry')
				count = 0
				for item2 in items2:

					timeentryid = item2.find('id').text
					todoitemid = item2.find('todo-item-id').text

					count = count + 1
					r.hset('Time_entry:' + timeentryid,'date',item2.find('date').text)
					r.hset('Time_entry:' + timeentryid,'description', item2.find('description').text)
					r.hset('Time_entry:' + timeentryid,'hours',item2.find('hours').text)
					r.hset('Time_entry:' + timeentryid,'id',item2.find('id').text)
					r.hset('Time_entry:' + timeentryid,'person-id',item2.find('person-id').text)
					r.hset('Time_entry:' + timeentryid,'project-id',item2.find('project-id').text)
					r.hset('Time_entry:' + timeentryid,'todo-item-id',item2.find('todo-item-id').text)

					r.zadd('Time_entry:' + projectid, int(item2.find('person-id').text),timeentryid)

					print i
					i = i + 1

					print item2.find('description').text

				if count != 50:
					break

				x = x + 1

			todosearch = bc.todo_lists_per_project(project_id = int(projectid), filter = 'all').text
			todo_lists = ET.fromstring(todosearch).findall('todo-list')
			for todo_list in todo_lists:
				#per todo list in a project
				listid = todo_list.find('id').text

				r.hset("Todo_list:" + listid,'id',listid)
				r.hset("Todo_list:" + listid,'name',todo_list.find('name').text)
				r.hset("Todo_list:" + listid,'project-id',todo_list.find('project-id').text)
				r.hset("Todo_list:" + listid,'completed',todo_list.find('completed').text)
				r.hset("Todo_list:" + listid,'completed-count',todo_list.find('completed-count').text)
				r.hset("Todo_list:" + listid,'uncompleted-count',todo_list.find('uncompleted-count').text)
				r.hset("Todo_list:" + listid,'position',todo_list.find('position').text)

				r.zadd('Todo_list:' + projectid, 1, listid)

				todoitemsearch = bc.items(list_id = int(listid)).text
				todo_items = ET.fromstring(todoitemsearch).findall('todo-item')
				for todo_item in todo_items:
					#per todo item in a todo list
					itemid = todo_item.find('id').text

					r.hset("Todo_item:" + itemid,'id',itemid)
					r.hset("Todo_item:" + itemid,'content',todo_item.find('content').text)
					r.hset("Todo_item:" + itemid,'todo-list-id',todo_item.find('todo-list-id').text)

					r.zadd('Todo_item:' + listid, 1, itemid)

			messagesearch = bc.messages_per_project(project_id = int(projectid)).text
			messages = ET.fromstring(messagesearch).findall('post')
			for message in messages:
				#per message in a project
				postid = message.find('id').text

				r.hset("Message:" + postid,'id',postid)

				body = message.find('body').text

				#parser = MessageParser()
				#parser.feed(body)

				#parsed_message = parser.output
				parsed_message = body

				r.hset("Message:" + postid,'body',parsed_message)
				r.hset("Message:" + postid,'author-id',message.find('author-id').text)
				r.hset("Message:" + postid,'project-id',message.find('body').text)
				r.hset("Message:" + postid,'title',message.find('title').text)
				r.hset("Message:" + postid,'posted-on',message.find('posted-on').text)
				r.hset("Message:" + postid,'category-id',message.find('category-id').text)
				r.hset("Message:" + postid,'category-name',message.find('category-name').text)
				r.hset("Message:" + postid,'attachments-count',message.find('attachments-count').text)

				if int(message.find('attachments-count').text) > 0:
					attachments = message.findall('attachment')
					
					attachment_count = 1
					for attachment in attachments:
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'id', attachment.find('id').text)
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'download-url', attachment.find('download-url').text)
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'project-id', attachment.find('project-id').text)
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'person-id', attachment.find('person-id').text)
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'name', attachment.find('name').text)
						attachment_count = attachment_count + 1

				r.zadd('Message:' + projectid, 1, postid)


			filesearch = bc.attachments(project_id = int(projectid)).text
			attachments = ET.fromstring(filesearch).findall('attachment')
			for attachment in attachments:
				#per attachment in a project
				attachmentid = attachment.find('id').text

				r.hset("Attachment:" + attachmentid,'id', attachment.find('id').text)
				r.hset("Attachment:" + attachmentid,'download-url', attachment.find('download-url').text)
				r.hset("Attachment:" + attachmentid,'project-id', attachment.find('project-id').text)
				r.hset("Attachment:" + attachmentid,'person-id', attachment.find('person-id').text)
				r.hset("Attachment:" + attachmentid,'name', attachment.find('name').text)


		for item in items:
			projectid = item.find('id').text

			projectpeople = bc.people_per_project(int(item.find('id').text)).text
			peoplesearch = ET.fromstring(projectpeople).findall('person')
			for person in peoplesearch:
				r.zadd("peopleperproject:" + projectid, int(person.find('id').text),person.find('email-address').text)
Beispiel #2
0
    def cacheData(self):
        r = redis.StrictRedis(host='localhost', port=6379, db=0)
        bc = Basecamp('https://seertechnologies.basecamphq.com',
                      self.api_token)
        i = 1
        userlist = {}

        xml = bc.people().text
        items = ET.fromstring(xml).findall('person')
        for item in items:
            #all users in seer
            r.hset(
                'Users:' + item.find('email-address').text, 'name',
                item.find('first-name').text + " " +
                item.find('last-name').text)
            r.hset('Users:' + item.find('email-address').text, 'id',
                   item.find('id').text)
            r.hset('Users:' + item.find('email-address').text, 'email',
                   item.find('email-address').text)

        xml = bc.projects().text
        items = ET.fromstring(xml).findall('project')
        for item in items:
            #all projects under seer
            projectname = item.find('name').text
            projectid = item.find('id').text
            print projectname
            print projectid

            r.hset('Projects:' + projectname, "name", projectname)
            r.hset('Projects:' + projectname, "id", projectid)

            r.zadd('Projects', 1, projectname)

            x = 1
            while 1:
                #every time log in a project
                time_entries_data = bc.time_entries_per_project(
                    project_id=int(projectid), page=x)

                if x > int(time_entries_data.headers['X-Pages']):
                    break

                time_entries = time_entries_data.text

                items2 = ET.fromstring(time_entries).findall('time-entry')
                count = 0
                for item2 in items2:

                    timeentryid = item2.find('id').text
                    todoitemid = item2.find('todo-item-id').text

                    count = count + 1
                    r.hset('Time_entry:' + timeentryid, 'date',
                           item2.find('date').text)
                    r.hset('Time_entry:' + timeentryid, 'description',
                           item2.find('description').text)
                    r.hset('Time_entry:' + timeentryid, 'hours',
                           item2.find('hours').text)
                    r.hset('Time_entry:' + timeentryid, 'id',
                           item2.find('id').text)
                    r.hset('Time_entry:' + timeentryid, 'person-id',
                           item2.find('person-id').text)
                    r.hset('Time_entry:' + timeentryid, 'project-id',
                           item2.find('project-id').text)
                    r.hset('Time_entry:' + timeentryid, 'todo-item-id',
                           item2.find('todo-item-id').text)

                    r.zadd('Time_entry:' + projectid,
                           int(item2.find('person-id').text), timeentryid)

                    print i
                    i = i + 1

                    print item2.find('description').text

                if count != 50:
                    break

                x = x + 1

            todosearch = bc.todo_lists_per_project(project_id=int(projectid),
                                                   filter='all').text
            todo_lists = ET.fromstring(todosearch).findall('todo-list')
            for todo_list in todo_lists:
                #per todo list in a project
                listid = todo_list.find('id').text

                r.hset("Todo_list:" + listid, 'id', listid)
                r.hset("Todo_list:" + listid, 'name',
                       todo_list.find('name').text)
                r.hset("Todo_list:" + listid, 'project-id',
                       todo_list.find('project-id').text)
                r.hset("Todo_list:" + listid, 'completed',
                       todo_list.find('completed').text)
                r.hset("Todo_list:" + listid, 'completed-count',
                       todo_list.find('completed-count').text)
                r.hset("Todo_list:" + listid, 'uncompleted-count',
                       todo_list.find('uncompleted-count').text)
                r.hset("Todo_list:" + listid, 'position',
                       todo_list.find('position').text)

                r.zadd('Todo_list:' + projectid, 1, listid)

                todoitemsearch = bc.items(list_id=int(listid)).text
                todo_items = ET.fromstring(todoitemsearch).findall('todo-item')
                for todo_item in todo_items:
                    #per todo item in a todo list
                    itemid = todo_item.find('id').text

                    r.hset("Todo_item:" + itemid, 'id', itemid)
                    r.hset("Todo_item:" + itemid, 'content',
                           todo_item.find('content').text)
                    r.hset("Todo_item:" + itemid, 'todo-list-id',
                           todo_item.find('todo-list-id').text)

                    r.zadd('Todo_item:' + listid, 1, itemid)

            messagesearch = bc.messages_per_project(
                project_id=int(projectid)).text
            messages = ET.fromstring(messagesearch).findall('post')
            for message in messages:
                #per message in a project
                postid = message.find('id').text

                r.hset("Message:" + postid, 'id', postid)

                body = message.find('body').text

                #parser = MessageParser()
                #parser.feed(body)

                #parsed_message = parser.output
                parsed_message = body

                r.hset("Message:" + postid, 'body', parsed_message)
                r.hset("Message:" + postid, 'author-id',
                       message.find('author-id').text)
                r.hset("Message:" + postid, 'project-id',
                       message.find('body').text)
                r.hset("Message:" + postid, 'title',
                       message.find('title').text)
                r.hset("Message:" + postid, 'posted-on',
                       message.find('posted-on').text)
                r.hset("Message:" + postid, 'category-id',
                       message.find('category-id').text)
                r.hset("Message:" + postid, 'category-name',
                       message.find('category-name').text)
                r.hset("Message:" + postid, 'attachments-count',
                       message.find('attachments-count').text)

                if int(message.find('attachments-count').text) > 0:
                    attachments = message.findall('attachment')

                    attachment_count = 1
                    for attachment in attachments:
                        r.hset(
                            "Attachment:" + postid + ":" +
                            str(attachment_count), 'id',
                            attachment.find('id').text)
                        r.hset(
                            "Attachment:" + postid + ":" +
                            str(attachment_count), 'download-url',
                            attachment.find('download-url').text)
                        r.hset(
                            "Attachment:" + postid + ":" +
                            str(attachment_count), 'project-id',
                            attachment.find('project-id').text)
                        r.hset(
                            "Attachment:" + postid + ":" +
                            str(attachment_count), 'person-id',
                            attachment.find('person-id').text)
                        r.hset(
                            "Attachment:" + postid + ":" +
                            str(attachment_count), 'name',
                            attachment.find('name').text)
                        attachment_count = attachment_count + 1

                r.zadd('Message:' + projectid, 1, postid)

            filesearch = bc.attachments(project_id=int(projectid)).text
            attachments = ET.fromstring(filesearch).findall('attachment')
            for attachment in attachments:
                #per attachment in a project
                attachmentid = attachment.find('id').text

                r.hset("Attachment:" + attachmentid, 'id',
                       attachment.find('id').text)
                r.hset("Attachment:" + attachmentid, 'download-url',
                       attachment.find('download-url').text)
                r.hset("Attachment:" + attachmentid, 'project-id',
                       attachment.find('project-id').text)
                r.hset("Attachment:" + attachmentid, 'person-id',
                       attachment.find('person-id').text)
                r.hset("Attachment:" + attachmentid, 'name',
                       attachment.find('name').text)

        for item in items:
            projectid = item.find('id').text

            projectpeople = bc.people_per_project(int(
                item.find('id').text)).text
            peoplesearch = ET.fromstring(projectpeople).findall('person')
            for person in peoplesearch:
                r.zadd("peopleperproject:" + projectid,
                       int(person.find('id').text),
                       person.find('email-address').text)
Beispiel #3
0
	def cacheData(self):

		getparams = {"token": "xoxp-2315794369-2421792110-2468567197-93f2c6","channel": "G02BLVCKM", "username": "******", "text": "```Starting to update Basecamp archives```" }
		req = requests.post('https://slack.com/api/chat.postMessage',params=getparams, verify=False)

		r = redis.StrictRedis(host='localhost',port=6379,db=0)
		bc = Basecamp('https://seertechnologies.basecamphq.com', self.api_token)
		i = 1
		userlist = {}

		xml = bc.people().text
		items = ET.fromstring(xml).findall('person')
		for item in items:
			#all users in seer
			r.hset('Users:' + item.find('email-address').text, 'name',item.find('first-name').text + " " + item.find('last-name').text)
			r.hset('Users:' + item.find('email-address').text, 'id',item.find('id').text)
			r.hset('Users:' + item.find('email-address').text, 'email',item.find('email-address').text)

			r.zadd('Users', 1,item.find('id').text)

			r.hset('Users:' + item.find('id').text, 'latestLog', "1970-01-01")
			r.hset('Users:' + item.find('id').text, 'email',item.find('email-address').text)
			

		xml = bc.projects().text
		items = ET.fromstring(xml).findall('project')
		for item in items:
			#all projects under seer
			projectname = item.find('name').text
			projectid = item.find('id').text

			r.hset('Projects:' + projectname,"name",projectname)
			r.hset('Projects:' + projectname,"id",projectid)

			r.zadd('Projects',1,projectname)

			x = 1
			while 1:
				#every time log in a project
				time_entries_data = bc.time_entries_per_project(project_id = int(projectid), page = x)

				if x > int(time_entries_data.headers['X-Pages']):
					break

				time_entries = time_entries_data.text

				items2 = ET.fromstring(time_entries).findall('time-entry')
				count = 0
				for item2 in items2:

					timeentryid = item2.find('id').text
					todoitemid = item2.find('todo-item-id').text

					count = count + 1
					r.hset('Time_entry:' + timeentryid,'date',item2.find('date').text)
					r.hset('Time_entry:' + timeentryid,'description', item2.find('description').text)
					r.hset('Time_entry:' + timeentryid,'hours',item2.find('hours').text)
					r.hset('Time_entry:' + timeentryid,'id',item2.find('id').text)
					r.hset('Time_entry:' + timeentryid,'person-id',item2.find('person-id').text)
					r.hset('Time_entry:' + timeentryid,'project-id',item2.find('project-id').text)
					r.hset('Time_entry:' + timeentryid,'todo-item-id',item2.find('todo-item-id').text)

					r.zadd('Time_entry:' + projectid, int(item2.find('person-id').text),timeentryid)

					logDate = datetime(int(item2.find('date').text[0:4]), int(item2.find('date').text[5:7]), int(item2.find('date').text[8:10]))
					dateToday = datetime.now()
					
					if dateToday.month==logDate.month and dateToday.year==logDate.year and dateToday.day-1==logDate.day:
						totalLogs = float(r.hget('Users:' + item2.find('person-id').text, 'totalLogsForTheWeek'))
						totalLogs = totalLogs + float(item2.find('hours').text)
						r.hset('Users:' + item2.find('person-id').text, 'totalLogsForTheWeek', totalLogs)
						r.hset('Users:' + item2.find('person-id').text, 'latestLog', item2.find('date').text)

					i = i + 1

				if count != 50:
					break

				x = x + 1

			todosearch = bc.todo_lists_per_project(project_id = int(projectid), filter = 'all').text
			todo_lists = ET.fromstring(todosearch).findall('todo-list')
			for todo_list in todo_lists:
				#per todo list in a project
				listid = todo_list.find('id').text

				r.hset("Todo_list:" + listid,'id',listid)
				r.hset("Todo_list:" + listid,'name',todo_list.find('name').text)
				r.hset("Todo_list:" + listid,'project-id',todo_list.find('project-id').text)
				r.hset("Todo_list:" + listid,'completed',todo_list.find('completed').text)
				r.hset("Todo_list:" + listid,'completed-count',todo_list.find('completed-count').text)
				r.hset("Todo_list:" + listid,'uncompleted-count',todo_list.find('uncompleted-count').text)
				r.hset("Todo_list:" + listid,'position',todo_list.find('position').text)

				r.zadd('Todo_list:' + projectid, 1, listid)

				todoitemsearch = bc.items(list_id = int(listid)).text
				todo_items = ET.fromstring(todoitemsearch).findall('todo-item')
				for todo_item in todo_items:
					#per todo item in a todo list
					itemid = todo_item.find('id').text

					r.hset("Todo_item:" + itemid,'id',itemid)
					r.hset("Todo_item:" + itemid,'content',todo_item.find('content').text)
					r.hset("Todo_item:" + itemid,'todo-list-id',todo_item.find('todo-list-id').text)

					r.zadd('Todo_item:' + listid, 1, itemid)

			messagesearch = bc.messages_per_project(project_id = int(projectid)).text
			messages = ET.fromstring(messagesearch).findall('post')
			for message in messages:
				#per message in a project
				postid = message.find('id').text

				r.hset("Message:" + postid,'id',postid)

				body = message.find('body').text

				#parser = MessageParser()
				#parser.feed(body)

				#parsed_message = parser.output
				parsed_message = body

				r.hset("Message:" + postid,'body',parsed_message)
				r.hset("Message:" + postid,'author-id',message.find('author-id').text)
				r.hset("Message:" + postid,'project-id',message.find('body').text)
				r.hset("Message:" + postid,'title',message.find('title').text)
				r.hset("Message:" + postid,'posted-on',message.find('posted-on').text)
				r.hset("Message:" + postid,'category-id',message.find('category-id').text)
				r.hset("Message:" + postid,'category-name',message.find('category-name').text)
				r.hset("Message:" + postid,'attachments-count',message.find('attachments-count').text)

				if int(message.find('attachments-count').text) > 0:
					attachments = message.findall('attachment')
					
					attachment_count = 1
					for attachment in attachments:
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'id', attachment.find('id').text)
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'download-url', attachment.find('download-url').text)
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'project-id', attachment.find('project-id').text)
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'person-id', attachment.find('person-id').text)
						r.hset("Attachment:" + postid + ":" + str(attachment_count),'name', attachment.find('name').text)
						attachment_count = attachment_count + 1

				r.zadd('Message:' + projectid, 1, postid)


			filesearch = bc.attachments(project_id = int(projectid)).text
			attachments = ET.fromstring(filesearch).findall('attachment')
			for attachment in attachments:
				#per attachment in a project
				attachmentid = attachment.find('id').text

				r.hset("Attachment:" + attachmentid,'id', attachment.find('id').text)
				r.hset("Attachment:" + attachmentid,'download-url', attachment.find('download-url').text)
				r.hset("Attachment:" + attachmentid,'project-id', attachment.find('project-id').text)
				r.hset("Attachment:" + attachmentid,'person-id', attachment.find('person-id').text)
				r.hset("Attachment:" + attachmentid,'name', attachment.find('name').text)


		for item in items:
			projectid = item.find('id').text

			projectpeople = bc.people_per_project(int(item.find('id').text)).text
			peoplesearch = ET.fromstring(projectpeople).findall('person')
			for person in peoplesearch:
				r.zadd("peopleperproject:" + projectid, int(person.find('id').text),person.find('email-address').text)

		getparams = {'token': self.slack_token,'pretty':'1'}
		req = requests.get('https://slack.com/api/users.list', params=getparams, verify=False)
		userlist = json.loads(req.content)
		for user in userlist['members']:
			r.hset('Slack:Users:' + user['profile']['email'], 'id', user['id'])


		getparams = {"token": "xoxp-2315794369-2421792110-2468567197-93f2c6","channel": "G02BLVCKM", "username": "******", "text": "```Basecamp updated!```" }
		req = requests.post('https://slack.com/api/chat.postMessage',params=getparams, verify=False)