def handle(self, *args, **options):
        opened = urllib2.urlopen(
            URL % (LANG, "\%23incidentratp+\%23ligne+\%23raison"))
        aggregated_result = ""
        for line in opened:
            aggregated_result += line

    #	print "result : %s " % (aggregated_result)
        extract_re = re.compile(PATTERN)
        loaded_document = json.loads(aggregated_result)
        for line in loaded_document['results']:
            try:
                print line['id_str'],
                (str_ligne, raison) = extract_re.findall(line['text'])[0]
                incident = Incident()
                ligne = Line.objects.get_or_create(name=str_ligne.strip())[0]
                incident.line = ligne
                incident.reason = raison.strip()
                incident.contributors = '(%s, %s)' % (line['id_str'],
                                                      line['from_user'])
                # test if incident exist
                incidents = Incident.objects.filter(line=ligne).filter(
                    contributors__icontains=incident.contributors)
                if len(incidents) != 0:
                    continue
                    print "existing"
                    incident = incidents[0]
                    incident.plus += 1
                    incident.contributors += ',(%s, %s)' % (line['id_str'],
                                                            line['from_user'])
                incident.save()
            except Exception as e:
                print str(e)
        print "done"
	def handle(self, *args, **options):
		opened = urllib2.urlopen(URL % (LANG, "\%23incidentratp+\%23ligne+\%23raison"))
		aggregated_result = ""
		for line in opened:
			aggregated_result += line
	#	print "result : %s " % (aggregated_result)
		extract_re = re.compile(PATTERN)
		loaded_document = json.loads(aggregated_result)
		for line in loaded_document['results']:
			try:
				print line['id_str'], 
				(str_ligne, raison) = extract_re.findall(line['text'])[0]
				incident = Incident()
				ligne = Line.objects.get_or_create(name=str_ligne.strip())[0]
				incident.line = ligne
				incident.reason = raison.strip()
				incident.contributors = '(%s, %s)' % (line['id_str'], line['from_user'])
				# test if incident exist
				incidents = Incident.objects.filter(line=ligne).filter(contributors__icontains = incident.contributors)
				if len(incidents) != 0:
					continue
					print "existing"
					incident = incidents[0]
					incident.plus += 1
					incident.contributors += ',(%s, %s)' % (line['id_str'], line['from_user'])
				incident.save()
			except Exception as e:
				print str(e)
		print "done"
Beispiel #3
0
	def handle(self, *args, **options):
		compiled_pattern = re.compile(PATTERN)
		#metro :
		print "metro"
		consolidated_text = ""
		for line in urllib2.urlopen(URL % METRO):
			consolidated_text += line
		print html2text(consolidated_text)[72:75]
		for result in compiled_pattern.findall(consolidated_text):
			(str_ligne, raison) = result
			incident = Incident()
			incident.line = Line.objects.get_or_create(name=str_ligne.strip())[0]
			incident.reason = raison.strip()
			incident.contributors = 'RATP'
		#rer :
		print "rer"
		consolidated_text = ""
		for line in urllib2.urlopen(URL % RER):
			consolidated_text += line

		for result in compiled_pattern.findall(consolidated_text):
			print result