Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Luis García
collabmap
Commits
a371643f
Commit
a371643f
authored
Feb 24, 2020
by
Luis García
Browse files
Twitter mining advances
parent
2e922859
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
4 deletions
+25
-4
project/social_networks.py
project/social_networks.py
+22
-2
project/views/api.py
project/views/api.py
+1
-1
requirements
requirements
+2
-1
No files found.
project/social_networks.py
View file @
a371643f
...
@@ -14,9 +14,29 @@ import json
...
@@ -14,9 +14,29 @@ import json
import
instaloader
import
instaloader
import
shutil
import
shutil
from
itertools
import
takewhile
,
dropwhile
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
=
OAuthHandler
(
config
(
'TWITTER_ID'
),
config
(
'TWITTER_SECRET'
))
auth
.
set_access_token
(
config
(
'TWITTER_ACCESS_TOKEN'
),
config
(
'TWITTER_ACCESS_TOKEN_SECRET'
))
auth
.
set_access_token
(
config
(
'TWITTER_ACCESS_TOKEN'
),
config
(
'TWITTER_ACCESS_TOKEN_SECRET'
))
api
=
tweepy
.
API
(
auth
)
api
=
tweepy
.
API
(
auth
)
query
=
"%23"
+
instance
.
code
surveys
=
consultation
.
surveys
.
all
()
\ No newline at end of file
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
project/views/api.py
View file @
a371643f
...
@@ -79,7 +79,7 @@ class ConsultationViewSet(DestroyToInvisibleMixin, OwnerFieldMixin, ModelViewSet
...
@@ -79,7 +79,7 @@ class ConsultationViewSet(DestroyToInvisibleMixin, OwnerFieldMixin, ModelViewSet
request
.
POST
.
_mutable
=
mutable
request
.
POST
.
_mutable
=
mutable
return
super
(
ConsultationViewSet
,
self
).
create
(
request
,
*
args
,
**
kwargs
)
return
super
(
ConsultationViewSet
,
self
).
create
(
request
,
*
args
,
**
kwargs
)
@
action
(
detail
=
True
,
methods
=
[
'
ge
t'
],
permission_classes
=
[
IsSuperOrReadOnly
])
@
action
(
detail
=
True
,
methods
=
[
'
pos
t'
],
permission_classes
=
[
IsSuperOrReadOnly
])
def
finish_consultation
(
self
,
request
,
pk
=
None
):
def
finish_consultation
(
self
,
request
,
pk
=
None
):
#Revisar esta parte
#Revisar esta parte
status
=
StatusMethod
(
'project_consultation'
).
last
()
status
=
StatusMethod
(
'project_consultation'
).
last
()
...
...
requirements
View file @
a371643f
...
@@ -21,4 +21,5 @@ requests==2.21.0
...
@@ -21,4 +21,5 @@ requests==2.21.0
instaloader==4.2.9
instaloader==4.2.9
drf-yasg==1.17.0
drf-yasg==1.17.0
drf-extensions==0.5.0
drf-extensions==0.5.0
django-cors-headers==3.1.1
django-cors-headers==3.1.1
\ No newline at end of file
django-allauth==0.41.0
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment