Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
plugins
twitter
Commits
a8e5a62a
Commit
a8e5a62a
authored
2 years ago
by
Eelco van der Wel
Browse files
Options
Download
Plain Diff
Merge branch 'dev' into 'qa'
Release 3.0.0 See merge request
!15
parents
d6ba3664
a56e041e
Pipeline
#11354
passed with stages
in 4 minutes and 54 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+1
-0
.gitlab-ci.yml
setup.py
+1
-1
setup.py
twitter/plugin.py
+5
-43
twitter/plugin.py
twitter/schema.py
+14
-19
twitter/schema.py
with
21 additions
and
63 deletions
+21
-63
.gitlab-ci.yml
+
1
-
0
View file @
a8e5a62a
...
...
@@ -26,6 +26,7 @@ build_image:
only
:
-
dev
-
qa
-
uat
-
prod
-
/release*/
stage
:
build
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
-
1
View file @
a8e5a62a
...
...
@@ -3,7 +3,7 @@ from setuptools import find_packages, setup
packages
=
find_packages
()
install_requires
=
[
"pymemri @ git+https://gitlab.memri.io/memri/pymemri.git@v0.0.
29
"
,
"pymemri @ git+https://gitlab.memri.io/memri/pymemri.git@v0.0.
31
"
,
"pytest ~= 7.1"
,
"tweepy @ git+https://github.com/alpdeniz/tweepy"
,
]
...
...
This diff is collapsed.
Click to expand it.
twitter/plugin.py
+
5
-
43
View file @
a8e5a62a
...
...
@@ -8,10 +8,9 @@ from time import sleep
from
.
import
helpers
from
.constants
import
*
from
pymemri.plugin.pluginbase
import
PluginBase
from
pymemri.data.oauth
import
OauthFlow
from
pymemri.plugin.states
import
RUN_USER_ACTION_NEEDED
,
RUN_USER_ACTION_COMPLETED
from
pymemri.data.schema
import
Edge
,
Account
,
Photo
,
Message
,
MessageChannel
from
.schema
import
Tweet
from
pymemri.data.schema
import
Edge
,
Photo
,
Message
,
MessageChannel
,
OauthFlow
from
.schema
import
Tweet
,
Account
logging
.
basicConfig
(
level
=
logging
.
WARNING
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -29,9 +28,6 @@ class TwitterPlugin(PluginBase):
self
.
edge_queue
=
[]
self
.
file_queue
=
[]
self
.
writing
=
False
# if callback_url is None:
# raise ValueError("need to pass callback_url")
# self.callback_url = callback_url
self
.
auth_item
=
None
def
setup
(
self
):
...
...
@@ -62,18 +58,8 @@ class TwitterPlugin(PluginBase):
sleep
(
0.5
)
oauth
.
set_access_token
(
self
.
auth_item
.
accessToken
,
self
.
auth_item
.
accessTokenSecret
)
# else:
# authorization_url = oauth.get_authorization_url()
# verifier = self.get_authorization_code(authorization_url)
# # print("AUTH URL:", authorization_url)
# # user-interaction below
# # verifier = input("Input PIN: ")
# access_token, access_token_secret = oauth.get_access_token(verifier)
# self.me.identifier = access_token
# self.me.secret = access_token_secret
# self.me.update(self.client)
self
.
api
=
tweepy
.
API
(
oauth
,
wait_on_rate_limit
=
True
)
# Update me
self
.
me
=
self
.
process_user
(
user
=
self
.
api
.
verify_credentials
(),
isMe
=
True
,
target_account
=
self
.
me
...
...
@@ -158,7 +144,7 @@ class TwitterPlugin(PluginBase):
logger
.
info
(
"[+] Twitter plugin run is completed"
)
logging
.
shutdown
()
def
process_user
(
self
,
user
=
None
,
isMe
=
None
,
target_account
=
None
):
def
process_user
(
self
,
user
,
isMe
=
None
,
target_account
=
None
):
"""
Cast twitter user into Memri account
"""
...
...
@@ -349,7 +335,7 @@ class TwitterPlugin(PluginBase):
self
.
pluginRun
.
authUrl
=
url
self
.
pluginRun
.
status
=
RUN_USER_ACTION_NEEDED
self
.
pluginRun
.
update
(
self
.
client
)
self
.
client
.
update
_item
(
self
.
pluginRun
)
# wait for user input
logger
.
info
(
"Waiting for user action"
)
while
self
.
pluginRun
.
status
!=
RUN_USER_ACTION_COMPLETED
:
...
...
@@ -366,29 +352,5 @@ class TwitterPlugin(PluginBase):
else
:
self
.
auth_item
=
oauth_items
[
0
]
# if externalId:
# search_filter['externalId'] = externalId
# if isMe is not None:
# search_filter['isMe'] = isMe
# result = client.search(search_filter)
# return result[0]
# OauthFlow
# if (
# self.pluginRun
# and self.pluginRun.account
# and len(self.pluginRun.account) > 0
# ):
# self.me = self.pluginRun.account[0]
# else:
# try:
# self.me = helpers.get_user(self.client, isMe=True)
# except:
# self.me = Account(service=SERVICE_NAME, isMe=True)
# self.client.create(self.me)
# if self.pluginRun:
# self.pluginRun.add_edge("account", self.me)
# self.pluginRun.update(self.client)
def
add_to_schema
(
self
):
self
.
client
.
add_to_schema
(
Account
,
Photo
,
Tweet
,
Message
,
MessageChannel
,
OauthFlow
)
This diff is collapsed.
Click to expand it.
twitter/schema.py
+
14
-
19
View file @
a8e5a62a
from
pymemri.data.schema
import
EdgeList
,
Post
,
Account
from
typing
import
Optional
from
datetime
import
datetime
from
typing
import
Optional
,
List
from
pymemri.data.schema
import
Item
,
Account
,
Photo
,
Website
class
Tweet
(
Post
):
class
Tweet
(
Item
):
message
:
Optional
[
str
]
=
None
service
:
Optional
[
str
]
=
None
postDate
:
Optional
[
datetime
]
=
None
description
=
"""Tweet of Twitter"""
properties
=
Post
.
properties
+
[
"service"
]
edges
=
Post
.
edges
+
[
"mention"
]
reply
:
List
[
"Tweet"
]
=
[]
links
:
List
[
"Website"
]
=
[]
mention
:
List
[
"Account"
]
=
[]
author
:
List
[
"Account"
]
=
[]
photo
:
List
[
"Photo"
]
=
[]
def
__init__
(
self
,
service
:
str
=
None
,
mention
:
EdgeList
[
"Account"
]
=
None
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
# Properties
self
.
service
:
Optional
[
str
]
=
service
# Edges
self
.
mention
:
EdgeList
[
"Account"
]
=
EdgeList
(
"mention"
,
"Account"
,
mention
)
\ No newline at end of file
class
Account
(
Account
):
description
:
Optional
[
str
]
=
None
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets