forked from alonmln/ILNewsDiff
-
Notifications
You must be signed in to change notification settings - Fork 0
Dor convensions #1
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
Open
db295
wants to merge
12
commits into
master
Choose a base branch
from
dor-convensions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3719cdc
Used some linter
820ae24
Remove the second gitignore
6847258
Moved logging into a file
d2d95f9
Moved parsers to the folder togther
34c3c44
Move img genrating code into a folder togther
b49302a
Comment about where might be the id bug
ff98a64
Process data initial commit
17ff3bb
Get database file as an argument
605e45c
Process data methods in dataProvider
a880f8e
Feature Extractors start
49360c5
Transfered from sqlite to csvs
3766558
Working better with pandas
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,5 +189,4 @@ dmypy.json | |
|
|
||
| *.log | ||
| titles.db* | ||
| *.html | ||
| *.png | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,50 @@ | ||
| # ILNewsDiff | ||
|
|
||
| See feed here: https://twitter.com/ILNewsDiff | ||
| See feed here: <https://twitter.com/ILNewsDiff> | ||
|
|
||
| **Interested in contributing to this project? Send us a direct message on [twitter](https://twitter.com/ILNewsDiff)** | ||
|
|
||
| A Twitter bot that keeps track of changes made in Israeli news websites. | ||
|
|
||
| Currently tracking: | ||
| * [Haaretz](https://www.haaretz.co.il/) | ||
| * [Israel Hayom](https://Israelhayom.co.il/) | ||
| * [Walla](https://www.walla.co.il/) | ||
|
|
||
| How does it work? | ||
| ------------ | ||
|
|
||
| * [Haaretz](https://www.haaretz.co.il/) | ||
| * [Israel Hayom](https://Israelhayom.co.il/) | ||
| * [Walla](https://www.walla.co.il/) | ||
|
|
||
| ## How does it work? | ||
|
|
||
| Once a minute the code queries news feeds and compares them to a previous state saved in a local SQLite DB. | ||
|
|
||
| If an _interesting_ change is found, a tweet is published with the diff. | ||
|
|
||
| The first tweet of a diff is always the article itself as a link, and all the subsequent changes are chained by order. | ||
| The first tweet of a diff is always the article itself as a link, and all the subsequent changes are chained by order. | ||
|
|
||
| ### What is _interesting_? | ||
|
|
||
| A change that | ||
| * Has happened and is not there because of a delay in the RSS feed. The code queries the article's page to look for the change. | ||
| * Is not comprised of only whitespace or punctuation. | ||
| * Has a difference of more than one letter (Though adding/removing a question mark '?' is interesting) | ||
|
|
||
|
|
||
| Installation | ||
| ------------ | ||
| + The [phantomjs](http://phantomjs.org/) binary needs to be installed, and the path updated in the run_diff.sh file. | ||
| + `pip install -r requirements.txt` | ||
| * Has happened and is not there because of a delay in the RSS feed. The code queries the article's page to look for the change. | ||
| * Is not comprised of only whitespace or punctuation. | ||
| * Has a difference of more than one letter (Though adding/removing a question mark '?' is interesting) | ||
|
|
||
| ## Installation | ||
|
|
||
| * The [phantomjs](http://phantomjs.org/) binary needs to be installed, and the path updated in the run_diff.sh file. | ||
| * `pip install -r requirements.txt` | ||
|
|
||
| [Twitter keys](https://dev.twitter.com/) are needed. | ||
|
|
||
| Credits | ||
| ------- | ||
| ## Credits | ||
|
|
||
| For contributing to this repo: | ||
|
|
||
| * [@yuvalpinter](https://github.com/yuvalpinter) | ||
|
|
||
| Based on @j-e-d's code for the Twitter bot [@nyt_diff](https://twitter.com/nyt_diff). | ||
| RSS feed fetching added for @xuv's Twitter bot [@lesoir_diff](https://twitter.com/lesoir_diff) | ||
|
|
||
| + Original script and idea: @j-e-d Juan E.D. http://unahormiga.com/ | ||
| + RSS fetching: @xuv Julien Deswaef http://xuv.be | ||
| + Font: [Merriweather](https://fonts.google.com/specimen/Merriweather) | ||
| + Background pattern: [Paper Fibers](http://subtlepatterns.com/paper-fibers/). | ||
| * Original script and idea: @j-e-d Juan E.D. <http://unahormiga.com/> | ||
| * RSS fetching: @xuv Julien Deswaef <http://xuv.be> | ||
| * Font: [Merriweather](https://fonts.google.com/specimen/Merriweather) | ||
| * Background pattern: [Paper Fibers](http://subtlepatterns.com/paper-fibers/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import logging | ||
| import os | ||
| import sys | ||
|
|
||
| if 'LOG_FOLDER' in os.environ: | ||
| LOG_FOLDER = os.environ['LOG_FOLDER'] | ||
| else: | ||
| LOG_FOLDER = '' | ||
|
|
||
|
|
||
| def setup_loggers(): | ||
| # Add Handlers | ||
| logging_filehandler = logging.FileHandler(filename=os.path.join(LOG_FOLDER, 'titlediff.log'), encoding='utf-8', mode='a+') | ||
| handlers = [logging_filehandler, logging.StreamHandler(sys.stdout)] | ||
| logging.basicConfig(handlers=handlers, | ||
| format='%(asctime)s %(name)13s %(levelname)8s: %(message)s', | ||
| level=logging.DEBUG) | ||
|
|
||
| # Handle some loggers | ||
| logging.getLogger("requests").setLevel(logging.WARNING) | ||
| logging.getLogger("selenium").setLevel(logging.WARNING) | ||
| logging.getLogger("PIL").setLevel(logging.WARNING) | ||
| logging.getLogger("requests_oauthlib").setLevel(logging.WARNING) | ||
| logging.getLogger("chardet").setLevel(logging.WARNING) | ||
| logging.getLogger("tweepy").setLevel(logging.WARNING) | ||
| logging.getLogger("oauthlib").setLevel(logging.WARNING) | ||
| logging.getLogger("urllib3").setLevel(logging.WARNING) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ def standard_entry_to_dict(article, source, tz, strip_description=False): | |
| else: | ||
| article_dict['abstract'] = article['description'] | ||
| od = collections.OrderedDict(sorted(article_dict.items())) | ||
| # The bug of the key?? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should fix the bug in the feature extractors and not here. |
||
| article_dict['hash'] = hashlib.sha224(repr(od.items()).encode('utf-8')).hexdigest() | ||
| article_dict['date_time'] = datetime.now(tz) | ||
| return article_dict | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import os | ||
| import pandas as pd | ||
|
|
||
|
|
||
| class CsvDataProvider: | ||
| def __init__(self, data_files=r"../csvs", version=0): | ||
| self._data_files_dir = data_files | ||
| self.articles = pd.read_csv(os.path.join(data_files, "articles.csv")) | ||
| self.versions_file_format = os.path.join(data_files, "versions_{version}.csv") | ||
| self.versions = pd.read_csv(self.versions_file_format.format(version=version)) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
|
|
||
| class FeatureExtractor(object): | ||
| def __init__(self) -> None: | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def get_cols() -> list: | ||
| return [] | ||
|
|
||
| @staticmethod | ||
| def extract(data, previous_data, article): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from feature_extractor import FeatureExtractor | ||
|
|
||
|
|
||
| class PrinterExtractor(FeatureExtractor): | ||
| @staticmethod | ||
| def extract(data, previous_data, article): | ||
| print(data) | ||
| return [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import argparse | ||
| import itertools | ||
|
|
||
| import pandas as pd | ||
|
|
||
| from printer_extractor import PrinterExtractor | ||
| from word_token_extractor import WordsTokensExtractor | ||
| from csv_data_provider import CsvDataProvider | ||
|
|
||
| COLUMNS_TO_KEEP = ["id", "version", "article_id", "article_source", "title", "amount_of_words"] | ||
|
|
||
| ROW_EXTRACTED = { | ||
| # "amount_of_words": WordsTokensExtractor.how_many_words | ||
| } | ||
|
|
||
| FEATURE_EXTRACTORS = [ | ||
| # WordsTokensExtractor, | ||
| # PrinterExtractor | ||
| ] | ||
|
|
||
|
|
||
| def process_data(data_files, clean_csv, out_version, in_version=0): | ||
| # TODO: choose which features to extract | ||
| dt = CsvDataProvider(data_files, in_version) | ||
|
|
||
| if clean_csv: | ||
| # The data we want to keep from the csvs | ||
| extracted_features = dt.versions[COLUMNS_TO_KEEP] | ||
| else: | ||
| extracted_features = dt.versions | ||
|
|
||
| # cols based on the same row data - | ||
| for col_name, f in ROW_EXTRACTED.items(): | ||
| extracted_features[col_name] = dt.versions.apply(f, axis=1, result_type="expand") | ||
|
|
||
| if len(FEATURE_EXTRACTORS) > 0: | ||
| # cols based on a lot of data - | ||
| cols = list(itertools.chain.from_iterable([extractor.get_cols() for extractor in FEATURE_EXTRACTORS])) | ||
| processed_data = pd.DataFrame(columns=cols) | ||
| row_id = 0 | ||
|
|
||
| # Extract Features | ||
| for _id, article in dt.articles.iterrows(): | ||
| article_versions = dt.versions[(dt.versions["article_id"] == article["article_id"]) & | ||
| (dt.versions["article_source"] == article["article_source"])] | ||
|
|
||
| for __id, single_version in article_versions.iterrows(): | ||
| past_versions = article_versions[article_versions["version"] < single_version["version"]] | ||
| processed_row = [] | ||
| for feature_extractor in FEATURE_EXTRACTORS: | ||
| processed_row.extend(feature_extractor.extract(single_version, past_versions, article)) | ||
|
|
||
| processed_data.loc[row_id] = processed_row | ||
| row_id += 1 | ||
|
|
||
| # TODO: export back to csv | ||
| print(f"Max words - {extracted_features['amount_of_words'].max()}") | ||
| out_file = dt.versions_file_format.format(version=out_version) | ||
| extracted_features.to_csv(out_file) | ||
|
|
||
| print("Done!!") | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description='Process some data.') | ||
| parser.add_argument('datafiles', help='A path to the folders with the csvs') | ||
| parser.add_argument('--in-version', default=0, help='Which version to use') | ||
| parser.add_argument('--out-version', help='Which version to write') | ||
|
|
||
| parser.add_argument('--clean', action="store_true", help='Should keep only important data') | ||
|
|
||
| args = parser.parse_args() | ||
| process_data(args.datafiles, args.clean, args.out_version, args.in_version) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont u need - try except ?