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
b5cc4444
Commit
b5cc4444
authored
May 02, 2019
by
Serbaf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added functions that allow to get dictionaries representing a subset of the…
Added functions that allow to get dictionaries representing a subset of the Tweet object information
parent
75fd7cb1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
8 deletions
+46
-8
HISTORY.rst
HISTORY.rst
+6
-0
setup.py
setup.py
+1
-1
tweet_model.py
tweet_model/tweet_model.py
+39
-7
No files found.
HISTORY.rst
View file @
b5cc4444
...
...
@@ -60,3 +60,9 @@ Version 0.4.4:
Fixed another requirement error
Version 0.4.5:
Changed f-strings to traditional strings for reasons of compatibility
Version 0.4.6:
Trying to track an error were Tweets are not instantiated if the CSV registry
contains certain symbols
Version 0.4.7:
Added function to generate dicts representing subsets of Tweet content (return
just the fields indicated by the user and not the full Tweet object)
setup.py
View file @
b5cc4444
...
...
@@ -51,6 +51,6 @@ setup(
test_suite
=
'tests'
,
tests_require
=
test_requirements
,
url
=
'https://github.com/Serbaf/tweet_model'
,
version
=
'0.4.
5
'
,
version
=
'0.4.
7
'
,
zip_safe
=
False
,
)
tweet_model/tweet_model.py
View file @
b5cc4444
...
...
@@ -2,6 +2,7 @@
"""Main module."""
import
logging
from
typing
import
Union
,
Dict
,
List
,
Generator
from
tweet_manager.lib
import
format_csv
...
...
@@ -395,13 +396,14 @@ def get_tweet_from_csv_line(header_fields, line_fields):
tweet_contents
[
header_fields
[
i
]
.
replace
(
"."
,
"__"
)]
=
\
line_fields
[
i
]
try
:
tweet
=
Tweet
(
**
tweet_contents
)
except
Exception
as
e
:
print
(
"An error of type "
+
type
(
e
)
.
__str__
+
"ocurred"
)
raise
Exception
return
tweet
# try:
# tweet = Tweet(**tweet_contents)
# except Exception as e:
# print("An error of type " + type(e).__str__ + "ocurred")
# raise Exception
#
# return tweet
return
Tweet
(
**
tweet_contents
)
def
get_tweets_from_csv
(
csv_file
):
...
...
@@ -446,3 +448,33 @@ def get_tweets_from_csv(csv_file):
tweets
.
append
(
get_tweet_from_csv_line
(
header_fields
,
line_fields
))
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
]
)
->
Generator
[
Dict
,
None
,
None
]:
"""
Given a list of Tweet objects, keep just the specified fields and
return a generator of dicts with just the information specified
"""
for
tweet
in
tweet_collection
:
yield
get_tweet_fields_subset
(
tweet
,
fields
)
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