-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
81 additions
and
843 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
__pycache__/ |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,47 @@ | ||
import os | ||
import json | ||
|
||
|
||
def merge_data(current_data, before_data): | ||
''' | ||
データをマージする | ||
param:current_data 現在のデータ | ||
param:before_data 過去のデータ | ||
''' | ||
tmp_obj = {} | ||
if current_data and before_data: | ||
concat_data = before_data + current_data | ||
for data in concat_data: | ||
tmp_obj[data.get('href')] = data.copy() | ||
merge_datas = [tmp_obj.get(title) for title in tmp_obj] | ||
return merge_datas | ||
elif current_data: | ||
return current_data | ||
else: | ||
return before_data | ||
|
||
|
||
def sort_articles(articles, sort_name): | ||
''' | ||
ソートする | ||
''' | ||
return sorted(articles, key=lambda x: int(x[sort_name]), reverse=False) | ||
|
||
|
||
def make_path(path): | ||
''' | ||
パスを作成する | ||
''' | ||
paths = path.split('/') | ||
if len(paths) > 1 and not os.path.exists('/'.join(paths[:-1])): | ||
os.makedirs('/'.join(paths[:-1])) | ||
return path | ||
|
||
|
||
def write_json_file(data, path): | ||
''' | ||
jsonファイル作成 | ||
''' | ||
jsonstr = json.dumps(data, ensure_ascii=False) | ||
with open(path, 'w', encoding='utf-8') as f: | ||
f.write(jsonstr) |