-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtester12a.py
More file actions
269 lines (180 loc) · 9.83 KB
/
tester12a.py
File metadata and controls
269 lines (180 loc) · 9.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#from bs4 import BeautifulSoup
from bs4 import BeautifulSoup
import urllib
import requests
import soupsieve as sv
import codecs
import csv
import io
import re
html_doc = urllib.request.urlopen('https://www.prisonpro.com/content/eastern-correctional-institution-annex').read()
soup = BeautifulSoup(html_doc, 'html.parser')
#print(soup.prettify())
head_tag = soup.head
#print(head_tag.contents)
title_tag = head_tag.contents[0]
#print(title_tag)
#for child in head_tag.descendants:
#print(child)
holding = []
#f = codecs.open('temptext.txt', encoding='utf-8',mode='w+')
for string in soup.strings:
holding.append(string)
#print(repr(string))
#f.write(string+'\n')
#'\n'
#f.close()
#print(holding)
print(len(holding))
index = holding.index('Inmate Mailing Address:')
print(index)
print(holding[57])
print(holding[58])
print(holding[59]) #this is the facility name
print(holding[60]) #this is street address
print(holding[61]) #this is city state and zip
print("ok nearly")
n = 5
entryToAdd = [n]
myPrison = ['Eastern', 'Western', 'Northern']
myStreet = ['123 east st.', '124 west st.', '125 north st.']
myZip = []
header = ['id', 'name', 'address', 'zip']
rows = [
[1, 'Hannah', '4891 Blackwell Street, Anchorage, Alaska', 99503 ],
[2, 'Walton', '4223 Half and Half Drive, Lemoore, California', 97401 ],
[3, 'Sam', '3952 Little Street, Akron, Ohio', 93704],
[4, 'Chris', '3192 Flinderation Road, Arlington Heights, Illinois', 62677],
[5, 'Doug', '3236 Walkers Ridge Way, Burr Ridge', 61257],
]
"""
with open('customers.csv', 'wt') as f:
csv_writer = csv.writer(f)
csv_writer.writerow(header) # write header
for row in rows:
csv_writer.writerow(row)
"""
names = []
addresses = []
zip = []
f = open('customers.csv', 'rt')
csv_reader = csv.DictReader(f, escapechar='\\')
#q = input("what name?")
for row in csv_reader:
#print(row['name'])
names.append(row['name'])
addresses.append(row['address'])
zip.append(row['zip'])
f.close
#if row['name'] == q:
#print("yes its here: " + q)
#else:
#print("nope not here")
#if q in row['name']:
#print("better?")
#else:
#pass
prisonToAdd = [holding[59], holding[60], holding[61]]
f2 = codecs.open('customers.csv', encoding='utf-8', mode='a')
#writer_object = csv.writer(f2)
#writer_object.writerow(prisonToAdd)
print(holding[61])
address = holding[61]
resulting = re.match('^.*(?P<zipcode>\d{5}).*$', address).groupdict()['zipcode']
print(resulting) #now we have zip code extracted from address
q2 = input("what anything to find?")
try:
locate = names.index(q2)
print("found!")
print(locate)
print(names[locate])
print(addresses[locate])
print(zip[locate])
except ValueError:
print("not found")
"""""
if row['name'] == 'Sam':
print('ok cool')
with open('prisonlist.csv', 'w', ) as myfile:
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
for word in myStreet:
wr.writerow([word])
"""""
#for string in soup.stripped_strings:
#print(repr(string))
#print("ok1.5")
#print("ok ---------------")
#link = soup.h2
#for parent in link.parents:
#print(parent.name)
#print(soup('h2'))
#print (soup.find_all('strong'))
#print("ok >>")
#print(soup.find('h2', text='Inmate Mailing Address:').text)
#print(soup.find('h2', text='Inmate Mailing Address:').parents)
#testing = []
#for EachPart in soup.select('div[class*="field__item"]'):
#testing.append(EachPart)
#print (EachPart.get_text())
#print(soup.select("[class~=sister]"))
print("ok <----->")
#print(testing)
#print(len(testing))
#print(testing[4])
#parent = soup.find(class_="field__item")
# assign n
#n = 2
# print the 2nd <b> of parent
#print(parent.select("h2:nth-of-type("+str(n)+")"))
#print(parent.select("div.text-formatted:nth-child(2)"))
# print the <b> which is the 2nd child of the parent
#print(parent.select("h2:nth-child("+str(n)+")"))
#print (soup.find('strong', text='Eastern Correctional Institution West and East Compounds').parent)
"""
div.text-formatted:nth-child(2)
html.js body.fontyourface.layout-one-sidebar.layout-sidebar-second.path-node.page-node-type-facility-page.mm-wrapper div#mm-0.mm-page.mm-slideout div.dialog-off-canvas-main-canvas div#page-wrapper div#page div#main-wrapper.layout-main-wrapper.layout-container.clearfix div#main.layout-main.clearfix main#content.column.main-content section.section div.region.region-content div#block-bartik-content.block.block-system.block-system-main-block div.content article.node.node--type-facility-page.node--promoted.node--view-mode-full.clearfix div.node__content.clearfix div.clearfix.text-formatted.field.field--name-body.field--type-text-with-summary.field--label-visually_hidden div.field__item h2
div.field__item:nth-child(2) > h2:nth-child(15)
div.field__item:nth-child(2) > h2:nth-child(15)
<div class="field__item"><h1> </h1><h1><img alt="Eastern Correctional Institution and Annex Maryland" src="https://www.prisonpro.com/images/eastern-correctional-institution.jpg" style="height:163px; width:250px"></h1><h1>Eastern Correctional Institution and Annex</h1><p>Eastern Correctional Institution and Annex is comprised of two facilities, the institution and the annex. Located in Westover Maryland, this prison can incarcerate over 3,500 adult males ranging in custody level from medium to pre-release security levels. Employing over 850 workers, this prison has a yearly budget of over $103 million dollars. This prison participates in the Maryland Correctional Enterprises allowing inmates to work in furniture restoration and in textiles making towels and washing clothing and uniforms. In addition, inmates can work on community projects restoring cemeteries and playgrounds.</p><p>While incarcerated inmates are encouraged to further their education through adult literacy and even earn a GED. Vocational training in masonry, automotive repair, architecture, graphic arts, carpentry and office technologies offer inmates a unique opportunity to learn a skill they can later use for employment. Offenders at Eastern Correctional Institution can also receive substance abuse treatment and counseling services.<a id="visitinghours" name="visitinghours"></a></p><p></p><div><div class="adsense responsive"><script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3874558055196722" data-ad-slot="3854553602" data-ad-format="auto" data-full-width-responsive="true"><iframe id="aswift_2" style="height: 1px !important; max-height: 1px !important; max-width: 1px !important; width: 1px !important;"><iframe id="google_ads_frame1"></iframe></iframe></ins><script>
<!--//--><![CDATA[// ><!--
(adsbygoogle = window.adsbygoogle || []).push({});
//--><!]]>
</script></div></div><h2>Visiting Hours at Eastern Correctional Institution & Annex:</h2><p><strong>Eastern Correctional Institution West and East Compounds</strong> have visitation on Fridays, Saturdays, and Sundays from 8:30am-2:30pm, you must arrive before 1:30pm or you will not be admitted to visitation.<br><strong>Eastern Correctional Institution Annex</strong> has visiting hours on Fridays from 5pm-9pm (must arrive and register by 8pm), and on Saturdays and Sundays from 9am-5pm (You must arrive and register by 4pm).<br><strong>Protective Custody Inmates</strong> have visitation on Fridays, Saturdays and Sundays from 7pm-9pm. You must arrive and be processed by 8pm or you will not be allowed to visit.</p><p>All visits are two hours in duration. Inmates can have a maximum of two visits per week, with up to five visitors, only three of the visitors can be adults. Disciplinary Segregation inmates are only allowed one single hour visit per week.</p><h2>Physical Address:</h2><p>Eastern Correctional Institution<br>30420 Revells Neck Road<br>Westover, Maryland 21890<br><br>Eastern Correctional Institution Annex<br>30430 Revells Neck Road<br>Westover, Maryland 21890</p><h2>Telephone:</h2><p>(410)-845-4000<br>(877)-802-6074</p><h2>Inmate Mailing Address:</h2><p>Inmate Name, ID Number<br><strong>Eastern Correctional Institution</strong><br>30420 Revells Neck Road<br>Westover, Maryland 21890<br><br>Inmate Name, ID Number<br><strong>Eastern Correctional Institution Annex</strong><br>30430 Revells Neck Road<br>Westover, Maryland 21890</p></div>
"""
#below is previous
#html_doc =
"""<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story">...</p>
"""
"""
soup = BeautifulSoup(html_doc, 'html.parser')
#print(soup.prettify())
print(soup.title)
print(soup.title.string)
for link in soup.find_all('a'):
print(link.get('href'))
print(soup.get_text())
/////////
def ddg(query):
#url = 'https://duckduckgo.com/html/'
url = 'https://www.prisonpro.com/search/node?keys='
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0'}
soup = BeautifulSoup(requests.get(url, params={'q':query}, headers=headers).content, 'html.parser')
while True:
for a in soup.select('.result__a'):
yield a['href']
f = soup.select_one('input[value="Next"]')
if not f:
break
params = {i['name']: i.get('value', '') for i in f.find_parent('form').select('input[name]')}
soup = BeautifulSoup(requests.post(url, params=params, headers=headers).content, 'html.parser')
for result in ddg('eastern'):
print(result)
"""