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

scraped telegram posts having line breaks like the original post #687

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mohammadali-seifkashani

When I tested snscrape for Telegram channels, I recognized that the posts don't have line breaks. And this caused problem for my text analysis. So I created the static method "get_post_text()" for that.

I also did a little cleaning in file code which are as follows:

  1. Remove redundant parentheses in conditions
  2. convert long lines to paragraphs

Copy link
Owner

@JustAnotherArchivist JustAnotherArchivist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the indentation and empty line changes, then I can review the other changes.

Copy link
Owner

@JustAnotherArchivist JustAnotherArchivist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation is still wrong and the diff unreadable.

@mohammadali-seifkashani
Copy link
Author

Please do a favor and check the code.

Copy link
Owner

@JustAnotherArchivist JustAnotherArchivist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup. The indentation of the new function is still incorrect though as it uses spaces, not tabs, so the code is a syntax error currently. Other things below.

Comment on lines -203 to +211
return cls._cli_construct(args, args.channel)
return cls._cli_construct(args, args.channel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still an undesired whitespace change. There should be a LF at the end of a (text-ish) file.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Looks like GitHub doesn't display this correctly on the PR page itself, only in the full diff: https://github.com/JustAnotherArchivist/snscrape/pull/687/files#diff-7f40c11448f92ed2f5d1764136d372d15faa3d4da0272813e88478c4d8870a09L203)

Comment on lines +148 to +152
result = []
# Using the features of the BS4 module itself
for s in post.stripped_strings:
result.append(s)
return '\n'.join(result)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to '\n'.join(post.stripped_strings), but it doesn't do the right thing anyway. It splits out links into separate lines, and it doesn't preserve multiple line breaks. A good test case for both is https://t.me/telegram/201. Looks like this might require explicitly replacing the <br> tags.

@@ -143,6 +143,14 @@ def get_items(self):
raise snscrape.base.ScraperException(f'Got status code {r.status_code}')
soup = bs4.BeautifulSoup(r.text, 'lxml')

@staticmethod
def get_post_text(post) -> str:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be message, not post, to avoid confusion with the variable in _soup_to_items. This should also not be public API. So _get_message_text(message).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module:telegram
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants