-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn.
74 lines (65 loc) · 2.38 KB
/
n.
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
import pywikibot
import requests
import time
def fetch_street_data(street_name):
try:
headers = {
'User-Agent': 'JustWikiBot/1.0 (your_email@example.com)' # Replace with your contact info
}
response = requests.get(
f'https://nominatim.openstreetmap.org/search?q={street_name}&format=json',
headers=headers
)
response.raise_for_status() # Raise an exception for HTTP errors
data = response.json()
if data:
return data[0] # Return the first result
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
except ValueError:
print("Error: Response is not valid JSON")
return None
def create_street_article(street_name, data):
# Create a MediaWiki article content template
article_content = f"""
{{Automated article}}
{{Infobox Price Chopper
| coordinates = {data.get('lat', 'Unknown')}, {data.get('lon', 'Unknown')}
| name = {street_name}
| image =
| storenumber =
| location = {data.get('display_name', 'Unknown')}
| address = TBD
| city_state = TBD
| opened = TBD
| closed = TBD
| store_type = TBD
| licensee = TBD
| replaced = TBD
| replaced_by = TBD
| previous = TBD
| next = TBD
}}
'''{street_name}''' is a location situated in {data.get('display_name', 'Unknown')}.
This article was automatically generated and may need further review or updates.
==References==
{{reflist}}
[[Category:Price Chopper stores in New York]]
[[Category:Supermarkets in Clay, New York]]
"""
return article_content
def main():
site = pywikibot.Site('en', 'justwiki') # Replace 'en' with the language code if necessary
street_names = ["Amarillo, Texas", "Another Street"] # Replace with your list of streets
for street_name in street_names:
data = fetch_street_data(street_name)
if data:
page = pywikibot.Page(site, street_name)
if not page.exists(): # Only create the page if it doesn't already exist
page.text = create_street_article(street_name, data)
page.save(f"Created article for {street_name}")
else:
print(f"The page for {street_name} already exists.")
time.sleep(1) # Add delay to respect API rate limits
if __name__ == "__main__":
main()