Skip to content
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

Rewrite of TXLeg.py along with .gitignoring config, csv files #1

Open
wants to merge 9 commits into
base: master
from

move multiline_strip to function library

  • Loading branch information
rsimoes committed Jan 27, 2016
commit f42c3a42ff002bd5527d02d10bb59d060da0eb9a
@@ -7,7 +7,12 @@
import csv
import os.path
import re
import sys

sys.path.append(
os.path.join(sys.path[0], '../../lib')
)
from govbot.util import multiline_strip

def get_tx_rep(url, body):

@@ -30,10 +35,10 @@ def get_tx_rep(url, body):


# Strip HTML tags, leading and trailing spaces on each line, redundant spacing:
def thorough_strip(string):
def multiline_strip(string):
string = re.sub(r'\<.+?>', '', string)
string = re.sub(r'[ \t]+', ' ', string)
string = re.sub(r'^[ \t]+|[ \t]+$', '', string, flags=re.MULTILINE)
string = re.sub(r'^\s+|\s+$', '', string, flags=re.MULTILINE)
string = re.sub('[\n\r]+', '\n', string)
return string

@@ -62,7 +67,7 @@ def rewrite_name(string):
str(member_info)
).group()

address = thorough_strip(
address = multiline_strip(
re.search(
r'Capitol Address:(.+?787\d{2})',
str(member_info),
@@ -169,8 +174,8 @@ def get_tx_leg():
csv = csv.DictWriter(
csv_file,
[
'District', 'Name', 'Party', 'Website', 'Phone',
'Address', 'Email', 'Facebook', 'Twitter'
'District', 'Name', 'Party', 'Website', 'Phone', 'Address',
'Email', 'Facebook', 'Twitter'
],
restval='',
lineterminator='\n'
No changes.
@@ -0,0 +1,8 @@
import re

# Strip leading and trailing spaces on each line, redundant spacing:
def multiline_strip(string):
string = re.sub(r'[ \t]+', ' ', string)
string = re.sub(r'^\s+|\s+$', '', string, flags=re.MULTILINE)
string = re.sub('[\n\r]+', '\n', string)
return string
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.