-
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
17 changed files
with
144 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[flake8] | ||
ignore = E203, E266, E501, W503, F403, F401, E402, E722, C901 | ||
max-line-length = 79 | ||
max-complexity = 18 | ||
select = B,C,E,F,W,T4,B9 |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
|
||
--- | ||
|
||
**What does happen/fail?** | ||
|
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
|
||
--- | ||
|
||
**What are you missing in citmetrics?** | ||
|
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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
### Actual behavior | ||
|
||
|
||
### Expected behavior | ||
|
||
|
||
### Steps to reproduce the behavior | ||
|
||
|
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,58 @@ | ||
fail_fast: true | ||
repos: | ||
- repo: meta | ||
hooks: | ||
- id: check-useless-excludes | ||
- repo: https://github.com/prettier/prettier | ||
rev: 2.0.5 | ||
hooks: | ||
- id: prettier | ||
files: \.(css|js|md|markdown|json) | ||
- repo: https://github.com/python/black | ||
rev: 19.10b0 | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.2.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-ast | ||
- id: check-case-conflict | ||
- id: check-executables-have-shebangs | ||
- id: check-json | ||
- id: check-merge-conflict | ||
- id: check-symlinks | ||
- id: check-vcs-permalinks | ||
- id: check-xml | ||
- id: check-yaml | ||
args: [--unsafe] | ||
- id: end-of-file-fixer | ||
- id: fix-encoding-pragma | ||
- id: forbid-new-submodules | ||
- id: requirements-txt-fixer | ||
- id: sort-simple-yaml | ||
- id: trailing-whitespace | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.8.3 | ||
hooks: | ||
- id: flake8 | ||
- repo: local | ||
hooks: | ||
- id: shfmt | ||
name: shfmt | ||
minimum_pre_commit_version: 2.4.0 | ||
language: golang | ||
additional_dependencies: | ||
- mvdan.cc/sh/v3/cmd/[email protected] | ||
entry: shfmt | ||
args: | ||
- -w | ||
- -i | ||
- '0' | ||
types: | ||
- shell | ||
|
||
- repo: https://github.com/asottile/blacken-docs | ||
rev: v1.7.0 | ||
hooks: | ||
- id: blacken-docs |
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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2017, 2018 Pablo Iranzo Gómez <[email protected]> |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2018 Pablo Iranzo Gómez <[email protected]> | ||
|
||
import json | ||
|
@@ -8,26 +8,32 @@ | |
|
||
def main(): | ||
files = [] | ||
folders = [os.getcwd()] # Walk the folders and subfolders for files based on our criteria | ||
folders = [ | ||
os.getcwd() | ||
] # Walk the folders and subfolders for files based on our criteria | ||
for folder in folders: | ||
for items in os.walk(folder, followlinks=True): | ||
root = items[0] | ||
filenames = items[2] | ||
|
||
for filename in filenames: | ||
filepath = os.path.join(root, filename) | ||
if os.path.splitext(filepath)[1] == '.txt' and '.json' in filename and 'risu' in filename: | ||
if ( | ||
os.path.splitext(filepath)[1] == ".txt" | ||
and ".json" in filename | ||
and "risu" in filename | ||
): | ||
files.append(filepath) | ||
|
||
for filename in files: | ||
contents = open(filename, 'r').read() | ||
contents = open(filename, "r").read() | ||
newcontents = "\n".join(contents.split("\n")[3:-2]) | ||
|
||
# Remove the .txt ending | ||
newfilename = "%s" % os.path.splitext(filename)[0] | ||
|
||
try: | ||
with open(newfilename, 'w') as fd: | ||
with open(newfilename, "w") as fd: | ||
json.dump(json.loads(newcontents), fd, indent=2) | ||
print("Converted successfully: %s" % newfilename) | ||
os.remove(filename) | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2018 Pablo Iranzo Gómez <[email protected]> | ||
# | ||
# Description: validate jsons as valid for risu or remove in case of corruption | ||
|
@@ -10,21 +10,23 @@ | |
|
||
def main(): | ||
files = [] | ||
folders = [os.getcwd()] # Walk the folders and subfolders for files based on our criteria | ||
folders = [ | ||
os.getcwd() | ||
] # Walk the folders and subfolders for files based on our criteria | ||
for folder in folders: | ||
for items in os.walk(folder, followlinks=True): | ||
root = items[0] | ||
filenames = items[2] | ||
|
||
for filename in filenames: | ||
filepath = os.path.join(root, filename) | ||
if os.path.splitext(filepath)[1] == '.json' and 'risu' in filename: | ||
if os.path.splitext(filepath)[1] == ".json" and "risu" in filename: | ||
files.append(filepath) | ||
|
||
for filename in files: | ||
print("Processing file: %s" % filename) | ||
try: | ||
json.load(open(filename, 'r')) | ||
json.load(open(filename, "r")) | ||
except: | ||
print("Processing failed, removing file") | ||
os.remove(filename) | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2018 Pablo Iranzo Gómez <[email protected]> | ||
|
||
import datetime | ||
|
@@ -16,7 +16,7 @@ def _set_headers(self): | |
:return: | ||
""" | ||
self.send_response(200) | ||
self.send_header('Content-type', 'text/html') | ||
self.send_header("Content-type", "text/html") | ||
self.end_headers() | ||
|
||
def do_GET(self): | ||
|
@@ -36,26 +36,29 @@ def do_POST(self): | |
""" | ||
Processes POST requests | ||
""" | ||
content_length = int(self.headers['Content-Length']) # <--- data size | ||
content_length = int(self.headers["Content-Length"]) # <--- data size | ||
post_data = self.rfile.read(content_length) # <--- Gets the data itself | ||
contents = post_data.decode('utf-8') | ||
filename = "risu-%s-%s.json" % (datetime.datetime.now().strftime("%Y%m%d-%H%M%S"), random.random()) | ||
contents = post_data.decode("utf-8") | ||
filename = "risu-%s-%s.json" % ( | ||
datetime.datetime.now().strftime("%Y%m%d-%H%M%S"), | ||
random.random(), | ||
) | ||
print("Incoming file: %s" % filename) | ||
|
||
try: | ||
with open(filename, 'w') as fd: | ||
with open(filename, "w") as fd: | ||
json.dump(json.loads(contents), fd, indent=2) | ||
except: | ||
try: | ||
with open(filename, 'w') as fd: | ||
with open(filename, "w") as fd: | ||
newdata = json.loads("\n".join(contents.split("\n")[3:-2])) | ||
json.dump(newdata, fd, indent=2) | ||
print("Old format of json detected and converted") | ||
|
||
except: | ||
# Corner case if we're getting something else we don't know about | ||
os.remove(filename) | ||
with open("%s.txt" % filename, 'w') as fd: | ||
with open("%s.txt" % filename, "w") as fd: | ||
fd.write(contents) | ||
print("Invalid format received") | ||
|
||
|
@@ -70,9 +73,9 @@ def run(server_class=HTTPServer, handler_class=S, port=80): | |
:param handler_class: | ||
:param port: | ||
""" | ||
server_address = ('', port) | ||
server_address = ("", port) | ||
httpd = server_class(server_address, handler_class) | ||
print('Starting httpd...') | ||
print("Starting httpd...") | ||
httpd.serve_forever() | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1 +1 @@ | ||
requests | ||
requests |
Oops, something went wrong.