Skip to content

Commit

Permalink
Added transfer functions for user, post and post_reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieboldianus committed Jun 6, 2018
1 parent df119bc commit 5fd7d4f
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 11 deletions.
7 changes: 6 additions & 1 deletion classes/fieldMapping.py
Expand Up @@ -80,6 +80,8 @@ def parseJsonRecord(jsonStringDict,origin,lbsnRecords):
elif place_type in ("city","neighborhood","admin"):
# city_guid
placeRecord = helperFunctions.createNewLBSNRecord_with_id(lbsnCity(),place.get('id'),origin)
if not place_type == "city":
placeRecord.sub_type = place_type
if not postGeoaccuracy or postGeoaccuracy == lbsnPost.COUNTRY:
postGeoaccuracy = lbsnPost.CITY
l_lng = lon_center
Expand All @@ -89,7 +91,7 @@ def parseJsonRecord(jsonStringDict,origin,lbsnRecords):
# place_guid
# For POIs, City is not available on Twitter
placeRecord = helperFunctions.createNewLBSNRecord_with_id(lbsnPlace(),place.get('id'),origin)
if not postGeoaccuracy or postGeoaccuracy == lbsnPost.CITY:
if not postGeoaccuracy or postGeoaccuracy in (lbsnPost.COUNTRY, lbsnPost.CITY):
postGeoaccuracy = lbsnPost.PLACE
l_lng = lon_center
l_lat = lat_center
Expand Down Expand Up @@ -143,6 +145,7 @@ def parseJsonRecord(jsonStringDict,origin,lbsnRecords):
postReactionRecord.reaction_like_count = jsonStringDict.get('favorite_count')
postReactionRecord.reaction_content = jsonStringDict.get('text')
postReactionRecord.reaction_type = postReaction.reaction_type
postReactionRecord.user_mentions_pkey.extend([userRef.pkey for userRef in refUserRecords])
if postReaction.reaction_type == lbsnPostReaction.REPLY:
refPostRecord = helperFunctions.createNewLBSNRecord_with_id(lbsnPost(),jsonStringDict.get('in_reply_to_status_id_str'),origin)
refUserRecord = helperFunctions.createNewLBSNRecord_with_id(lbsnUser(),jsonStringDict.get('in_reply_to_user_id_str'),origin)
Expand All @@ -151,6 +154,8 @@ def parseJsonRecord(jsonStringDict,origin,lbsnRecords):
refPostRecord = helperFunctions.createNewLBSNRecord_with_id(lbsnPost(),jsonStringDict.get('quoted_status_id_str'),origin)
elif postReaction.reaction_type == lbsnPostReaction.SHARE:
refPostRecord = helperFunctions.createNewLBSNRecord_with_id(lbsnPost(),jsonStringDict.get('retweeted_status').get('id_str'),origin)
if refPostRecord:
lbsnRecords.AddRecordsToDict(refPostRecord)
postReactionRecord.referencedPost_pkey.CopyFrom(refPostRecord.pkey)
# ToDo: if a Reaction refers to another reaction (Information Spread)
# This information is currently not [available from Twitter](https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/tweet-object):
Expand Down
11 changes: 10 additions & 1 deletion classes/helperFunctions.py
Expand Up @@ -107,7 +107,16 @@ def null_check(recordAttr):
return None
else:
return recordAttr


def null_check_datetime(recordAttr):
if not recordAttr:
return None
else:
if recordAttr.ToDatetime() == datetime.datetime(1970, 1, 1, 0, 0, 0):
return None
else:
return recordAttr.ToDatetime()

def geoconvertOrNone(geom):
if geom:
return "ST_GeomFromText(%s,4326)"
Expand Down

0 comments on commit 5fd7d4f

Please sign in to comment.