Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upOWTwitterGraph: Add a new widget #22
Conversation
rokgomiscek
added some commits
Dec 9, 2016
kernc
requested changes
Dec 16, 2016
| **Outputs**: | ||
|
|
||
| - **Followers Graph** | ||
| A graph of users that follow the selected users. |
This comment has been minimized.
This comment has been minimized.
| CONSUMER_SECRET = CredentialManager('Twitter API Secret').key | ||
| OAUTH_TOKEN = '' | ||
| OAUTH_TOKEN_SECRET = '' | ||
| auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET) |
This comment has been minimized.
This comment has been minimized.
kernc
Dec 16, 2016
Member
This crashes with:
Traceback (most recent call last):
File "/home/u/orange3/networks/orangecontrib/network/widgets/OWNxTwitterGraph.py", line 112, in fetch_users
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
File "/home/u/venv/orange3/lib/python3.4/site-packages/twitter/oauth.py", line 97, in __init__
'You must supply strings for token_secret and consumer_secret, not None.')
twitter.auth.MissingCredentialsError: You must supply strings for token_secret and consumer_secret, not None.
This comment has been minimized.
This comment has been minimized.
ajdapretnar
Dec 16, 2016
Contributor
Confirmed, have an error message "Please, provide an API key." here.
| from Orange.widgets import widget, gui | ||
| from Orange.data import Domain, StringVariable, Table | ||
| import numpy as np | ||
| from Orange.widgets.credentials import CredentialManager |
This comment has been minimized.
This comment has been minimized.
| import numpy as np | ||
| from Orange.widgets.credentials import CredentialManager | ||
| import orangecontrib.network as network | ||
| from orangecontrib.text import twitter as txt_twitter |
This comment has been minimized.
This comment has been minimized.
kernc
Dec 16, 2016
Member
It's not common we do this. Add-ons are unreliable, at best. In particular, I don't think they make any API guarantees. If the sole reason for this is twitter API key validation, I assume, for lack of proper documentation, that the twitter lib should fail on OAuth handshake if the access token were incorrect?
This comment has been minimized.
This comment has been minimized.
ajdapretnar
Jan 11, 2017
Contributor
This would probably fail if the user doesn't have Text add-on installed, too. Could/should we re-implement this here as well?
| from PyQt4 import QtGui, QtCore | ||
| from collections import defaultdict | ||
|
|
||
| class OWNxTwitterGraph(widget.OWWidget): |
This comment has been minimized.
This comment has been minimized.
| followers_graph = nx.Graph() | ||
| following_graph = nx.Graph() | ||
| all_users = nx.Graph() | ||
| users = self.users.toPlainText().split("\n") |
This comment has been minimized.
This comment has been minimized.
kernc
Dec 16, 2016
Member
Could this be split on commas as well? Or perhaps with regex on all characters that aren't on twitter username whitelist?
This comment has been minimized.
This comment has been minimized.
ajdapretnar
Jan 11, 2017
Contributor
Wouldn't this make things all too complicated? Current implementation in Text is newline as well, so I vote for keeping this for now.
This comment has been minimized.
This comment has been minimized.
kernc
Jan 11, 2017
Member
Complicated is a relative term.
users = re.split('[^\w_]+', self.users.toPlainText())
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
kernc
Jan 12, 2017
Member
Must be something in the way you specify users. This just splits on characters not in (A-Z, a-z, 0-9, and _), might need adapting (to accept @ or skip empty strings or something like that). Point was: it's not necessarily complicated.
|
|
||
| fwers_names=[] | ||
| fwing_names=[] | ||
| all_names=[] |
This comment has been minimized.
This comment has been minimized.
| all_names=[] | ||
|
|
||
| for user in users: | ||
| result = t.users.show(screen_name=user) |
This comment has been minimized.
This comment has been minimized.
| result = t.users.show(screen_name=user) | ||
| id = result["id"] | ||
|
|
||
| if id in mapping.keys(): |
This comment has been minimized.
This comment has been minimized.
| followers_graph.add_node(user_fwer_id) | ||
| following_graph.add_node(user_fwing_id) | ||
| all_users.add_node(user_all_id) | ||
|
|
This comment has been minimized.
This comment has been minimized.
kernc
Dec 16, 2016
Member
Could you high-level comment a bit what's going on in each block of this long method?
This comment has been minimized.
This comment has been minimized.
|
I tested this and I have a few requests. Did a checklist, probably @nikicc can help with many of them.
Otherwise, I love the improvements you've made, especially the labeling! |
nikicc
reviewed
Dec 16, 2016
| self.button = gui.button(box, self, "Create graph", self.fetch_users) | ||
|
|
||
| def open_key_dialog(self): | ||
| self.api_dlg.exec_() |
This comment has been minimized.
This comment has been minimized.
nikicc
Dec 16, 2016
Contributor
If this is the only thing this method does, we can just provide self.api_dlg.exec_ as a callback to the button above and delete this method.
|
|
||
| if id in mapping.keys(): | ||
| user_fwer_id, user_fwing_id, user_all_id = mapping[id] | ||
| if not user_fwer_id: |
This comment has been minimized.
This comment has been minimized.
nikicc
Dec 16, 2016
Contributor
Could we move the code of this and the following if into a method? They seem to be doing the same thing.
| all_users.add_node(user_all_id) | ||
|
|
||
| cursor = -1 | ||
| while cursor != 0: |
This comment has been minimized.
This comment has been minimized.
nikicc
Dec 16, 2016
Contributor
Same here; could the code from this and the following while be moved to a common method?
This comment has been minimized.
This comment has been minimized.
|
@rokgomiscek Could we get this working in about two weeks so we can include it in the tutorial for DH or would it be better to wait (and skip it)? |
This comment has been minimized.
This comment has been minimized.
|
I've fixed most of @kernc's requests, still working on your requests. I'll try to push the fixes on Friday. |
PrimozGodec
referenced this pull request
Oct 27, 2017
Closed
[WIP] OWTwitterNetwork: Add a new widget #45
This comment has been minimized.
This comment has been minimized.
|
@rokgomiscek, any plans to finish this? |


rokgomiscek commentedDec 15, 2016
Issue
Added widget for creating network of twitter users.
Description of changes
Widget takes a list of twitter users and searches for their followers and friends.
Includes