-
Notifications
You must be signed in to change notification settings - Fork 70
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
4 changed files
with
64 additions
and
3 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,38 @@ | ||
import os | ||
import shlex | ||
from tqdm import tqdm | ||
import shutil | ||
import subprocess | ||
from subprocess import STDOUT, check_output | ||
|
||
from extstats.CONSTS import CRX_DIRECTORY as DIR | ||
from distutils.version import LooseVersion | ||
|
||
DESTINATION = 'crawled/sources/{ext_id}/{version}' | ||
|
||
def sort_semverfiles(files): | ||
def keyfunc(filename): | ||
return LooseVersion(filename.replace('.zip', '')) | ||
return sorted(files, key=keyfunc) | ||
|
||
for ext in os.listdir(DIR): | ||
files = os.listdir(DIR + ext) | ||
files_details = [] | ||
latest = sort_semverfiles(files)[-1] | ||
fullpath = DIR + ext + '/' + latest | ||
size = os.path.getsize(fullpath) | ||
if size > 100000000: #100mb | ||
continue | ||
print(fullpath, size) | ||
dest = DESTINATION.format(ext_id=ext, version=latest.replace('.zip', '')) | ||
try: | ||
shutil.rmtree(dest) | ||
except FileNotFoundError: | ||
pass | ||
os.makedirs(dest, exist_ok=True) | ||
try: | ||
check_output('unzip {} -d {}'.format(shlex.quote(fullpath), shlex.quote(dest)), timeout=60, shell=True) | ||
except subprocess.CalledProcessError as e: | ||
print('error:', e.returncode, ' - ', e.cmd) | ||
except subprocess.TimeoutExpired: | ||
pass |
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ tqdm | |
jinja2 | ||
arrow | ||
beautifulsoup4 | ||
elasticsearch_dsl | ||
elasticsearch_dsl | ||
flask |
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,21 @@ | ||
import flask | ||
from flask import request | ||
import subprocess | ||
import time | ||
|
||
app = flask.Flask(__name__) | ||
|
||
@app.route('/') | ||
def index(): | ||
q = request.args.get('q') | ||
def inner(): | ||
proc = subprocess.Popen( | ||
['ag', str(q), 'crawled/sources/'], | ||
stdout=subprocess.PIPE | ||
) | ||
for line in iter(proc.stdout.readline, ''): | ||
yield line.rstrip().decode('utf8')+'\n' | ||
|
||
return flask.Response(inner(), mimetype='text/text') | ||
|
||
app.run(debug=True, port=5000) |