Commit a371643f authored by Luis García's avatar Luis García
Browse files

Twitter mining advances

parent 2e922859
......@@ -14,9 +14,29 @@ import json
import instaloader
import shutil
from itertools import takewhile, dropwhile
from surveys.models import SocialInput
def TwitterMining(instance):
def TwitterMining(consultation):
auth = OAuthHandler(config('TWITTER_ID'), config('TWITTER_SECRET'))
auth.set_access_token(config('TWITTER_ACCESS_TOKEN'), config('TWITTER_ACCESS_TOKEN_SECRET'))
api = tweepy.API(auth)
query = "%23"+instance.code
\ No newline at end of file
surveys = consultation.surveys.all()
for survey in surveys:
questions = survey.survey_questions.all()
for question in questions:
#If is a collabmap question minin its data
if question.question.type == 'cm':
query = "%23"+consultation.slug
query = '#{slug1} #{slug2} #{slug2}'.format(slug1=consultation.phase.slug, slug2=consultation.slug, slug3=question.question.spatial_data.all()[0].slug)
results = api.search(q=query, result_type='recent')
for tweet in results:
location = False
if tweet.coordinates:
location = GEOSGeometry(str(tweet.coordinates))
#If the location not exist, calculate the center for the place box
elif tweet.place:
box = tweet.place.bounding_box
location = Polygon.from_bbox((box.origin()[0], box.origin()[1], box.corner()[0], box.corner()[1])).centroid
if location:
input = SocialInput(description='')
input.save()
\ No newline at end of file
......@@ -79,7 +79,7 @@ class ConsultationViewSet(DestroyToInvisibleMixin, OwnerFieldMixin, ModelViewSet
request.POST._mutable = mutable
return super(ConsultationViewSet, self).create(request, *args, **kwargs)
@action(detail=True, methods=['get'], permission_classes=[IsSuperOrReadOnly])
@action(detail=True, methods=['post'], permission_classes=[IsSuperOrReadOnly])
def finish_consultation(self, request, pk=None):
#Revisar esta parte
status = StatusMethod('project_consultation').last()
......
......@@ -22,3 +22,4 @@ instaloader==4.2.9
drf-yasg==1.17.0
drf-extensions==0.5.0
django-cors-headers==3.1.1
django-allauth==0.41.0
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment