Skip to content
This repository has been archived by the owner on Nov 24, 2019. It is now read-only.

Commit

Permalink
Strip URLs out of contents field of Steam API return
Browse files Browse the repository at this point in the history
Bump up content length limit in MHW & Rocket League to compensate
  • Loading branch information
sco1 committed Sep 28, 2018
1 parent 85d243d commit 3fe943d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bot/cogs/mhw.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def getofficialnews(self, appID: int=None) -> typing.List:
"""
appID = appID if appID is not None else self.appID

news = await SteamNewsPost.asyncgetnewsforapp(appID=appID, count=15, maxlength=500)
news = await SteamNewsPost.asyncgetnewsforapp(appID=appID, count=15, maxlength=600)
logging.info(f"{len(news)} MHW news posts returned by Steam's API")
officialnews = [item for item in news if self.MHWnewsfilter(item, self.officialaccount)]

Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/rocketleague.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def getofficialnews(self, appID: int=None) -> typing.List:
"""
appID = appID if appID is not None else self.appID

news = await SteamNewsPost.asyncgetnewsforapp(appID=appID, count=15, maxlength=500)
news = await SteamNewsPost.asyncgetnewsforapp(appID=appID, count=15, maxlength=600)
logging.info(f"{len(news)} RL news post(s) returned by Steam's API")
officialnews = [item for item in news if self.RLnewsfilter(item, self.psyonixstaff)]

Expand Down
11 changes: 10 additions & 1 deletion bot/models/Steam.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import re
import typing
from datetime import datetime

Expand All @@ -18,7 +19,7 @@ def __init__(self, gid: str=None, title: str=None, url: str=None, is_external_ur
self.url = URL(url)
self.is_external_url = is_external_url
self.author = author
self.contents = contents
self.contents = self._stripURL(contents)
self.feedlabel = feedlabel
self.date = datetime.fromtimestamp(date)
self.feedname = feedname
Expand Down Expand Up @@ -52,3 +53,11 @@ def getnewsforapp(appID: int=582010, count: int=10, maxlength: int=300,

if rawdict['appnews'] and rawdict['appnews']['newsitems']:
return [SteamNewsPost(**item) for item in rawdict['appnews']['newsitems']]

@staticmethod
def _stripURL(instr: str) -> str:
"""
Strip URLs out of instr using a basic regex
"""
exp = r"https?:\/\/[\w\-\.\/]+\s?"
return re.sub(exp, '', instr)

0 comments on commit 3fe943d

Please sign in to comment.