-
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathgenerate_readme.py
More file actions
executable file
·170 lines (125 loc) · 6.54 KB
/
generate_readme.py
File metadata and controls
executable file
·170 lines (125 loc) · 6.54 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
#!/usr/bin/env python3
import json
import urllib.parse
def format_query_for_display(query):
"""Format query for display in the README."""
if not query.strip():
return "```dsl\n\n```"
# Ensure proper formatting with triple backticks
return f"```dsl\n{query}\n```"
def create_url_for_query(query, virtual_hosts=False):
"""Create a URL-encoded query for Censys search."""
encoded_query = urllib.parse.quote_plus(query)
base_url = "https://search.censys.io/search?resource=hosts"
# Add virtual_hosts parameter if needed
if virtual_hosts:
return f"{base_url}&virtual_hosts=INCLUDE&q={encoded_query}&ref=awesome-censys-queries"
else:
return f"{base_url}&q={encoded_query}&ref=awesome-censys-queries"
def format_references(references):
"""Format references as a list for the README."""
if not references:
return ""
ref_str = "<details>\n <summary markdown=\"span\">References</summary>\n\n"
for ref in references:
ref_str += f"- <{ref}>\n"
ref_str += "\n</details>"
return ref_str
def format_notes(notes):
"""Format additional notes for the README."""
if not notes:
return ""
return "\n".join(notes)
def format_screenshot(screenshot):
"""Format a screenshot detail section for the README."""
if not screenshot:
return ""
alt_text = screenshot.split("/")[-1].split(".")[0]
return f"<details>\n <summary markdown=\"span\">Screenshot</summary>\n <img src=\"{screenshot}\" alt=\"{alt_text}\" width=\"500px\" />\n</details>"
def generate_readme():
"""Generate the README.md content from queries.json."""
with open('queries.json') as f:
data = json.load(f)
# Start with the header content
readme = """# Awesome Censys Queries
[](https://awesome.re)
[](https://results.pre-commit.ci/latest/github/thehappydinoa/awesome-censys-queries/main)
[](https://github.com/thehappydinoa/awesome-censys-queries/graphs/contributors)
[](https://github.com/thehappydinoa/awesome-censys-queries/stargazers)
[](#license)

A collection of fascinating and bizarre [Censys Search](https://search.censys.io?ref=awesome-censys-queries) queries.
<!-- markdownlint-disable MD033 -->
<p align="center">
<img src="./images/search.censys.io.png" alt="Censys Search" width="500px" />
</p>
## Contributing
Found an awesome query? [Submit it here](https://github.com/thehappydinoa/awesome-censys-queries/issues/new?assignees=thehappydinoa&labels=query+submissions&template=query-submission.md&title=)
Interested in contributing in another way? [See the contributing guidelines](CONTRIBUTING.md)
## Resources
- [Censys Search](https://search.censys.io?ref=awesome-censys-queries)
- [CensysGPT Beta - AI Generated Queries](https://gpt.censys.io?utm_source=github&utm_medium=awesome-censys-queries&utm_campaign=awesome-censys-queries)
- [Legacy Search Queries](https://github.com/thehappydinoa/awesome-censys-queries/tree/legacy-search-queries) - For queries compatible with the legacy Censys search syntax
## Key
- <a>🔎 →</a> - This icon will take you to the Censys Search results page for the query.
## Table of Contents
<!-- markdownlint-disable MD004 MD005 MD007 MD032 -->
<!-- toc -->
"""
# Generate the table of contents
for category in data['categories']:
readme += f" * [{category['name']}](#{category['name'].lower().replace(' ', '-')})\n"
readme += """- [Credits](#credits)
- [License](#license)
- [Star History](#star-history)
<!-- tocstop -->
<!-- markdownlint-enable MD004 MD005 MD007 MD032 -->
"""
# Generate content for each category
for category in data['categories']:
readme += f"### {category['name']}\n\n"
for query in category['queries']:
# Create the encoded URL for the query
virtual_hosts = query.get('virtual_hosts', False)
url = create_url_for_query(query['query'], virtual_hosts)
# Add the query section
readme += f"#### {query['title']} [🔎 →]({url})\n\n"
readme += format_query_for_display(query['query']) + "\n\n"
# Add notes if present
if query.get('notes'):
notes = [note for note in query.get('notes') if note] # Filter out empty notes
for i, note in enumerate(notes):
readme += f"> {note}"
# If it's the last note or the only note, add double newline
# Otherwise, add single newline between notes
if i == len(notes) - 1:
readme += "\n\n" # Double newline after last note
else:
readme += "\n" # Single newline between notes
# Add screenshot if present
if query.get('screenshot'):
readme += format_screenshot(query['screenshot']) + "\n\n"
# Add references if present
if query.get('references'):
readme += format_references(query['references']) + "\n\n"
# Add credits section
readme += "## Credits\n\n"
for i, credit in enumerate(data['metadata']['credits']):
url = data['metadata']['credit_urls'][i] if i < len(data['metadata']['credit_urls']) else ""
if url:
readme += f"- [{credit}]({url})\n"
else:
readme += f"- {credit}\n"
# Add license and star history sections
readme += """
## License
[](https://creativecommons.org/publicdomain/zero/1.0/)
## Star History
[](https://star-history.com/#thehappydinoa/awesome-censys-queries&Date)
"""
# Write the README content to a file
with open('README.md', 'w') as f:
f.write(readme)
print("README.md generated successfully!")
if __name__ == "__main__":
generate_readme()