Skip to content

Commit

Permalink
Merge branch 'master' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
hurshd0 committed Apr 26, 2020
2 parents ac47045 + 8661e05 commit 7ddc97c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
30 changes: 10 additions & 20 deletions api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)



###############################################################################
#
# Root Endpoint
Expand Down Expand Up @@ -122,8 +123,7 @@ async def post_gnews(news: NewsInput) -> JSONResponse:
except DataReadingError as ex:
_logger.warning(f"Endpoint: /news --- POST --- {ex}")
return JSONResponse(
status_code=404,
content={"message": f"[Error] post /News API: {ex}"}
status_code=404, content={"message": f"[Error] post /News API: {ex}"}
)

return json_data
Expand Down Expand Up @@ -184,8 +184,7 @@ async def get_twitter() -> JSONResponse:
gc.collect()
except Exception as ex:
_logger.warning(f"Endpoint: /twitter --- GET --- {ex}")
raise HTTPException(status_code=404,
detail=f"[Error] get /twitter API: {ex}")
raise HTTPException(status_code=404, detail=f"[Error] get /twitter API: {ex}")

return json_data

Expand Down Expand Up @@ -213,13 +212,11 @@ async def post_twitter(twyuser: TwitterInput) -> JSONResponse:
"tweets": tweets,
},
}

del tweets
gc.collect()
except Exception as ex:
_logger.warning(f"Endpoint: /twitter --- POST --- {ex}")
raise HTTPException(status_code=404,
detail=f"[Error] post /twitter API: {ex}")
raise HTTPException(status_code=404, detail=f"[Error] post /twitter API: {ex}")

return json_data

Expand Down Expand Up @@ -273,7 +270,6 @@ async def get_county_data() -> JSONResponse:
raise HTTPException(
status_code=404,
detail=f"[Error] get '/county' API: {ex}")

return json_data


Expand All @@ -293,8 +289,7 @@ def post_county(county: CountyInput) -> JSONResponse:
gc.collect()
except Exception as ex:
_logger.warning(f"Endpoint: /county --- POST --- {ex}")
raise HTTPException(status_code=404,
detail=f"[Error] get '/county' API: {ex}")
raise HTTPException(status_code=404, detail=f"[Error] get '/county' API: {ex}")

return json_data

Expand Down Expand Up @@ -338,8 +333,7 @@ async def post_state(state: StateInput) -> JSONResponse:
gc.collect()
except Exception as ex:
_logger.warning(f"Endpoint: /state --- POST --- {ex}")
raise HTTPException(status_code=404,
detail=f"[Error] get /country API: {ex}")
raise HTTPException(status_code=404, detail=f"[Error] get /country API: {ex}")

return json_data

Expand Down Expand Up @@ -380,8 +374,7 @@ async def get_country(country: CountryInput) -> JSONResponse:
json_data = {"success": True, "message": data}
except Exception as ex:
_logger.warning(f"Endpoint: /country --- GET --- {ex}")
raise HTTPException(status_code=404,
detail=f"[Error] get /country API: {ex}")
raise HTTPException(status_code=404, detail=f"[Error] get /country API: {ex}")

return json_data

Expand Down Expand Up @@ -423,8 +416,7 @@ async def get_stats() -> JSONResponse:
json_data = {"success": True, "message": data}
except Exception as ex:
_logger.warning(f"Endpoint: /stats --- GET --- {ex}")
raise HTTPException(status_code=404,
detail=f"[Error] get /stats API: {ex}")
raise HTTPException(status_code=404, detail=f"[Error] get /stats API: {ex}")
return json_data


Expand All @@ -442,8 +434,7 @@ async def post_stats(stats: StatsInput) -> JSONResponse:
json_data = {"success": True, "message": data}
except Exception as ex:
_logger.warning(f"Endpoint: /stats --- POST --- {ex}")
raise HTTPException(status_code=404,
detail=f"[Error] post /stats API: {ex}")
raise HTTPException(status_code=404, detail=f"[Error] post /stats API: {ex}")
return json_data


Expand Down Expand Up @@ -515,7 +506,6 @@ def post_zip(zip_code: ZIPInput) -> JSONResponse:
gc.collect()
except Exception as ex:
_logger.warning(f"Endpoint: /zip --- POST --- {ex}")
raise HTTPException(status_code=404,
detail=f"[Error] get '/zip' API: {ex}")
raise HTTPException(status_code=404, detail=f"[Error] get '/zip' API: {ex}")

return json_data
7 changes: 2 additions & 5 deletions api/utils/gnews.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from api.config import app_config


def get_state_topic_google_news(state: str,
topic: str,
max_rows: int = 10) -> Dict:
def get_state_topic_google_news(state: str, topic: str, max_rows: int = 10) -> Dict:
"""This function takes a US State name (string dtype) and a topic of
interest (string dtype). The output is a pandas DataFrame with articles,
urls, and publishing times for articles containing the state and topic
Expand Down Expand Up @@ -79,8 +77,7 @@ def get_us_news(max_rows: int = 50) -> Dict:
df = pd.DataFrame(df[["title", "url", "publishedAt"]])
df = df.rename(columns={"publishedAt": "published"})
# Infer datetime
df["published"] = pd.to_datetime(df["published"],
infer_datetime_format=True)
df["published"] = pd.to_datetime(df["published"], infer_datetime_format=True)
# Assuming timedelta of 5 hr based on what comparison between CNN and API.
df["published"] = df["published"] - pd.Timedelta("5 hours")

Expand Down

0 comments on commit 7ddc97c

Please sign in to comment.