Skip to content

Commit

Permalink
Add flake8 and fix whitespace problems
Browse files Browse the repository at this point in the history
  • Loading branch information
nobuhibiki committed Nov 1, 2016
1 parent 3ea6f05 commit 0124f7c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 38 deletions.
28 changes: 28 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[flake8]
ignore =
# Module imported but unused
F401,
# Line too long
E501,
# Indentation contains tabs
W191,
ZZZZ # allow comma on last entry
select =
# Missing whitespace around modulo
E228,
# Blank line at end of file
W391,
# Block comment should start with '# '
E265,
# Whitespace before '('
E211,
# Trailing whitespace
W291,
# Multiple spaces after operator
E222,
# Multiple imports on one line
E401,
# Indentation contains mixed spaces and tabs
E101,
ZZZZ # allow comma on last entry
filename = *.py
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ jdk:
env:
global:
- secure: DbveaxDMtEP+/Er6ktKCP+P42uDU8xXWRBlVGaqVNU3muaRmmZtj8ngAARxfzY0f9amlJlCavqkEIAumQl9BYKPWIra28ylsLNbzAoCIi8alf9WLgddKwVWsTcZo9+UYocuY6UivJVkofycfFJ1blw/83dWMG0/TiW6s/SrwoDw=
install:
- pip install --user flake8
script:
- "./gradle_init.sh"
- gradle assemble
- "./gradle_clean.sh"
- ant
- bin/start.sh
# Run flake8
- flake8 bin
before_script:
- pip install --user codecov
install: true
after_success:
- sh .utility/push-javadoc-to-gh-pages.sh
- bash <(curl -s https://codecov.io/bash)
Expand Down
11 changes: 5 additions & 6 deletions bin/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
query = "http://127.0.0.1:9000/api/search.json?q={}".format(searchTerm)

try:
fetchData = urllib.urlopen(query).read()
fetchData = urllib.urlopen(query).read()
except Exception, e:
print "! Sorry, something went wrong:"
print "! Error: %s"%e
sys.exit(1)
print "! Sorry, something went wrong:"
print "! Error: %s" % e
sys.exit(1)

statuses = json.loads(fetchData).get("statuses")
texts = [tweet.get("text") for tweet in statuses]

for text in texts:
print text

print text
14 changes: 7 additions & 7 deletions bin/search_fossasia.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Returns all tweet text lines related to fossasia
# Returns all tweet text lines related to fossasia
import urllib
from urllib import request
import html
Expand All @@ -9,21 +9,21 @@
search_term = sys.argv[1]
query = "http://loklak.org/api/search.json?q={}".format(search_term)

#get file and decode
# Get file and decode
try:
json_data = urllib.request.Request(query)
with urllib.request.urlopen(json_data) as data:
data1 = str(data.read().decode('utf-8'))
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
data1 = data1.translate(non_bmp_map)
except Exception as e:
print ("! Sorry, something went wrong:")
print ("! Error: %s"%e)
sys.exit(1)
print("! Sorry, something went wrong:")
print("! Error: %s" % e)
sys.exit(1)

#output tweets
# Output tweets
statuses = json.loads(data1).get("statuses")
texts = [tweet.get("text") for tweet in statuses]

for text in texts:
print (text)
print(text)
16 changes: 9 additions & 7 deletions bin/search_nerdwithak.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#Uses Python3
import urllib.request, json, sys
# Uses Python3
import urllib.request
import json
import sys

#Get JSON file
# Get JSON file
data = urllib.request.urlopen("127.0.0.1:9000/api/search.json?q=%s" % (sys.argv[1]))

#Read and parse JSON
# Read and parse JSON
data = data.read().decode('utf-8')
data = json.loads(data)

#Print out tweets
for tweet in data["statuses"]:
print(tweet["text"])
# Print out tweets
for tweet in data["statuses"]:
print(tweet["text"])
34 changes: 17 additions & 17 deletions bin/test_piotr.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#!/usr/bin/python
#!/usr/bin/python
import os
import requests


def print_response_from_file(file_name, path):
current_file = open(path + file_name, 'r', encoding="utf8")
for line in current_file:
response = requests.get("http://127.0.0.1:9000/api/search.json?q=" + line)
x = response.json()
try:
print(x['statuses'])
except Exception as e:
print(e)
current_file = open(path + file_name, 'r', encoding="utf8")
for line in current_file:
response = requests.get("http://127.0.0.1:9000/api/search.json?q=" + line)
x = response.json()
try:
print(x['statuses'])
except Exception as e:
print(e)


def print_all_files_lines_in_defined_directory(path):
for fn in os.listdir(path):
if fn == 'README.txt':
pass
elif fn.endswith(".txt"):
print_response_from_file(fn, path)
else:
pass
for fn in os.listdir(path):
if fn == 'README.txt':
pass
elif fn.endswith(".txt"):
print_response_from_file(fn, path)
else:
pass


if __name__ == "__main__":
print_all_files_lines_in_defined_directory('../test/queries/')
print_all_files_lines_in_defined_directory('../test/queries/')

0 comments on commit 0124f7c

Please sign in to comment.