Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tweet_model
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
serpucga
tweet_model
Commits
9e03adab
Commit
9e03adab
authored
May 14, 2019
by
Serbaf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added method to represent tweet as json
parent
a5bc9c99
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
19 deletions
+31
-19
tweet.py
tweet_model/tweet.py
+30
-0
utils.py
tweet_model/utils.py
+1
-19
No files found.
tweet_model/tweet.py
View file @
9e03adab
# -*- coding: utf-8 -*-
"""Main module."""
import
json
import
pysnooper
from
typing
import
List
,
Dict
class
Tweet
():
"""
...
...
@@ -366,5 +371,30 @@ class Tweet():
def
set_trtext
(
self
,
trtext
):
self
.
trtext
=
trtext
def
get_tweet_fields_subset
(
self
,
fields
:
List
[
str
])
->
Dict
:
"""
Keep just the specified fields and return a dict
with just the information specified
"""
tweet_subset
=
{}
for
field
in
fields
:
try
:
tweet_subset
[
field
]
=
self
[
field
]
except
AttributeError
:
pass
return
tweet_subset
def
as_json
(
self
)
->
Dict
:
"""
Return the Tweet object in a JSON-like representation (nested dicts)
"""
json_tweet
=
{}
for
key
,
value
in
self
.
__dict__
.
items
():
if
value
is
not
None
:
json_tweet
[
key
]
=
value
return
json_tweet
def
__getitem__
(
self
,
key
):
return
getattr
(
self
,
key
)
tweet_model/utils.py
View file @
9e03adab
...
...
@@ -92,24 +92,6 @@ def get_tweets_from_csv(csv_file):
return
tweets
def
get_tweet_fields_subset
(
tweet
:
Tweet
,
fields
:
List
[
str
]
)
->
Dict
:
"""
Given a Tweet objects, keep just the specified fields and return a dict
with just the information specified
"""
tweet_subset
=
{}
for
field
in
fields
:
try
:
tweet_subset
[
field
]
=
tweet
[
field
]
except
AttributeError
:
pass
return
tweet_subset
def
get_tweet_collection_fields_subset
(
tweet_collection
:
Union
[
List
[
Tweet
],
Generator
[
Tweet
,
None
,
None
]],
fields
:
List
[
str
]
...
...
@@ -119,7 +101,7 @@ def get_tweet_collection_fields_subset(
return a generator of dicts with just the information specified
"""
for
tweet
in
tweet_collection
:
yield
get_tweet_fields_subset
(
tweet
,
fields
)
yield
tweet
.
get_tweet_fields_subset
(
fields
)
class
NotValidTweetError
(
Exception
):
...
...
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