-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp_runQueries.py
More file actions
185 lines (139 loc) · 7.09 KB
/
Copy pathexp_runQueries.py
File metadata and controls
185 lines (139 loc) · 7.09 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
import argparse
import logging
import textwrap
from typing import Optional
import feedparser
import pandas as pd
import datetime
import requests
import subprocess
from failures.articles.models import Article, SearchQuery
from failures.commands.scrape import ScrapeCommand
from failures.commands.classifyAnalyzable import ClassifyAnalyzableCommand
from failures.commands.classifyFailure import ClassifyFailureCommand
from failures.commands.merge import MergeCommand
class exp_RunQueriesCommand:
def prepare_parser(self, parser: argparse.ArgumentParser):
# add description
parser.description = textwrap.dedent(
"""
Collect and populate articles from Google News RSS feed for conducting experiments.
"""
)
def run(self, args: argparse.Namespace, parser: argparse.ArgumentParser):
self.CollectIncidents(args, parser)
def CollectIncidents(self, args: argparse.Namespace, parser: argparse.ArgumentParser):
logging.info("\nExperiment: Collecting articles")
scrape_parser = argparse.ArgumentParser()
classifyFailure_parser = argparse.ArgumentParser()
classifyAnalyzable_parser = argparse.ArgumentParser()
merge_parser = argparse.ArgumentParser()
Scrape_Command = ScrapeCommand()
Scrape_Command.prepare_parser(scrape_parser)
ClassifyFailure_Command = ClassifyFailureCommand()
ClassifyFailure_Command.prepare_parser(classifyFailure_parser)
classifyFailure_options = []
classifyFailure_args = classifyFailure_parser.parse_args(classifyFailure_options)
ClassifyAnalyzable_Command = ClassifyAnalyzableCommand()
ClassifyAnalyzable_Command.prepare_parser(classifyAnalyzable_parser)
classifyAnalyzable_options = []
classifyAnalyzable_args = classifyAnalyzable_parser.parse_args(classifyAnalyzable_options)
Merge_Command = MergeCommand()
Merge_Command.prepare_parser(merge_parser)
merge_options = []
merge_args = merge_parser.parse_args(merge_options)
# Define arrays of keywords and date ranges
keywords = [
"software fail",
"software hack",
"software bug",
"software fault",
"software error",
"software exception",
"software crash",
"software glitch",
"software defect",
"software incident",
"software flaw",
"software mistake",
"software anomaly",
"software side effect"
]
# 1. DEFINE THE YEARS
# logic: range(start, stop) includes start but EXCLUDES stop.
# To run for just 2024, use range(2024, 2025).
# To run for 2023 and 2024, use range(2023, 2025).
start_years = list(range(2023, 2025))
end_years = list(range(2023, 2025))
# 2. DEFINE THE MONTHS (Full Year Jan-Dec)
# We need a start date and an end date for every query.
# The script loops through these two lists simultaneously (zips them).
# start_months: [1, 2, ..., 12]
# This sets the beginning of the search window (January 1st, Feb 1st, etc.)
start_months = list(range(1, 13))
# end_months: [2, 3, ..., 13]
# This sets the cutoff of the search window.
# range(2, 14) generates numbers 2 through 13.
# Important: The number '13' triggers specific logic in the script to
# wrap around to "January of the NEXT year" (capturing all of December).
end_months = list(range(2, 14))
sources = [
"wired.com",
"nytimes.com",
"cnn.com",
"dailymail.co.uk",
"theguardian.com",
"bbc.com",
"foxnews.com", #https://pressgazette.co.uk/media-audience-and-business-data/media_metrics/most-popular-websites-news-world-monthly-2/, https://pressgazette.co.uk/media-audience-and-business-data/media_metrics/most-popular-websites-news-world-monthly-2/
"apnews.com",
"washingtonpost.com",
"cnet.com",
"reuters.com", #Identification of sources of failures and their propagation in critical infrastructures from 12 years of public failure reports
]
# Iterate through all combinations of keywords, years, and months
for start_year, end_year in zip(start_years, end_years):
for start_month, end_month in zip(start_months, end_months):
if end_month == 13: #For December 01 to January 01
start_month = 12
end_month = 1
end_year = end_year + 1
for keyword in keywords:
for source in sources:
scrape_options = ["--sources", source,
"--keyword", keyword,
"--start-year", str(start_year),
"--end-year", str(end_year),
"--start-month", str(start_month),
"--end-month", str(end_month),
]
scrape_args = scrape_parser.parse_args(scrape_options)
Scrape_Command.run(scrape_args, scrape_parser)
#ClassifyFailure_Command.run(classifyFailure_args, classifyFailure_parser)
#ClassifyAnalyzable_Command.run(classifyAnalyzable_args, classifyAnalyzable_parser)
#Merge_Command.run(merge_args, merge_parser)
'''
def RerunIncidentPipelineByYear(self, args: argparse.Namespace, parser: argparse.ArgumentParser):
logging.info("\nExperiment: Rerunning Pipeline by Year (to correct ClassifyFailure from temp=1 to temp=0)")
classifyFailure_parser = argparse.ArgumentParser()
classifyAnalyzable_parser = argparse.ArgumentParser()
merge_parser = argparse.ArgumentParser()
ClassifyFailure_Command = ClassifyFailureCommand()
ClassifyFailure_Command.prepare_parser(classifyFailure_parser)
ClassifyAnalyzable_Command = ClassifyAnalyzableCommand()
ClassifyAnalyzable_Command.prepare_parser(classifyAnalyzable_parser)
classifyAnalyzable_options = []
classifyAnalyzable_args = classifyAnalyzable_parser.parse_args(classifyAnalyzable_options)
Merge_Command = MergeCommand()
Merge_Command.prepare_parser(merge_parser)
merge_options = []
merge_args = merge_parser.parse_args(merge_options)
years = list(range(2022, 2023))
# Iterate through all combinations of keywords, years, and months
for year in years:
logging.info("\n Pipeline for year: " + str(year))
classifyFailure_options = ["--year", str(year)]
classifyFailure_args = classifyFailure_parser.parse_args(classifyFailure_options)
ClassifyFailure_Command.run(classifyFailure_args, classifyFailure_parser)
ClassifyAnalyzable_Command.run(classifyAnalyzable_args, classifyAnalyzable_parser)
Merge_Command.run(merge_args, merge_parser)
'''