Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes SyntaxWarning errors in regex #231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions twitter/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def delete_scheduled_tweet(self, tweet_id: int) -> dict:
return self.gql('POST', Operation.DeleteScheduledTweet, variables)

def clear_scheduled_tweets(self) -> None:
user_id = int(re.findall('"u=(\d+)"', self.session.cookies.get('twid'))[0])
user_id = int(re.findall(r'"u=(\d+)"', self.session.cookies.get('twid'))[0])
drafts = self.gql('GET', Operation.FetchScheduledTweets, {"ascending": True})
for _id in set(find_key(drafts, 'rest_id')):
if _id != user_id:
Expand All @@ -790,7 +790,7 @@ def delete_draft_tweet(self, tweet_id: int) -> dict:
return self.gql('POST', Operation.DeleteDraftTweet, variables)

def clear_draft_tweets(self) -> None:
user_id = int(re.findall('"u=(\d+)"', self.session.cookies.get('twid'))[0])
user_id = int(re.findall(r'"u=(\d+)"', self.session.cookies.get('twid'))[0])
drafts = self.gql('GET', Operation.FetchDraftTweets, {"ascending": True})
for _id in set(find_key(drafts, 'rest_id')):
if _id != user_id:
Expand Down Expand Up @@ -829,7 +829,7 @@ def fleetline(self, params: dict = None) -> dict:
@property
def id(self) -> int:
""" Get User ID """
return int(re.findall('"u=(\d+)"', self.session.cookies.get('twid'))[0])
return int(re.findall(r'"u=(\d+)"', self.session.cookies.get('twid'))[0])

def save_cookies(self, fname: str = None):
""" Save cookies to file """
Expand Down
12 changes: 6 additions & 6 deletions twitter/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def _get_chunks(self, location: str) -> list[str]:
headers={'authority': url.host}
)
# don't need an m3u8 parser
chunks = re.findall('\n(chunk_.*)\n', r.text, flags=re.I)
chunks = re.findall(r'\n(chunk_.*)\n', r.text, flags=re.I)
url = '/'.join(location.split('/')[:-1])
return [f'{url}/{chunk}' for chunk in chunks]
except Exception as e:
Expand Down Expand Up @@ -546,7 +546,7 @@ async def process(data: list[dict]) -> list:
[streams.setdefault(_id, []).append(chunk) for _id, chunk in chunks]
# ensure chunks are in correct order
for k, v in streams.items():
streams[k] = sorted(v, key=lambda x: int(re.findall('_(\d+)_\w\.aac$', x.url.path)[0]))
streams[k] = sorted(v, key=lambda x: int(re.findall(r'_(\d+)_\w\.aac$', x.url.path)[0]))
out = self.out / 'audio'
out.mkdir(parents=True, exist_ok=True)
for space_id, chunks in streams.items():
Expand Down Expand Up @@ -717,7 +717,7 @@ async def _space_listener(self, chat: dict, frequency: int):
print()
print(f"({rand_color()}{user}{RESET})")
prev_user = user
new_message = re.sub(f'^({prev_message})', '', message, flags=re.I).strip()
new_message = re.sub(fr'^({prev_message})', '', message, flags=re.I).strip()
if len(new_message) < 100:
print(new_message, end=' ')
prev_message = message
Expand Down Expand Up @@ -771,9 +771,9 @@ def spaces_live(self, rooms: list[str]):
@param rooms: list of room ids
@return: None
"""
chunk_idx = lambda chunk: re.findall('_(\d+)_\w\.aac', chunk)[0]
chunk_idx = lambda chunk: re.findall(r'_(\d+)_\w\.aac', chunk)[0]
sort_chunks = lambda chunks: sorted(chunks, key=lambda x: int(chunk_idx(x)))
parse_chunks = lambda txt: re.findall('\n(chunk_.*)\n', txt, flags=re.I)
parse_chunks = lambda txt: re.findall(r'\n(chunk_.*)\n', txt, flags=re.I)

async def get_m3u8(client: AsyncClient, space: dict) -> dict:
try:
Expand Down Expand Up @@ -894,7 +894,7 @@ def _validate_session(self, *args, **kwargs):
@property
def id(self) -> int:
""" Get User ID """
return int(re.findall('"u=(\d+)"', self.session.cookies.get('twid'))[0])
return int(re.findall(r'"u=(\d+)"', self.session.cookies.get('twid'))[0])

def save_cookies(self, fname: str = None):
""" Save cookies to file """
Expand Down