Skip to content

Instantly share code, notes, and snippets.

@AaronErhardt
Last active October 11, 2022 14:27
Show Gist options
  • Save AaronErhardt/7661074ef221efd5862c602f17cfa827 to your computer and use it in GitHub Desktop.
Save AaronErhardt/7661074ef221efd5862c602f17cfa827 to your computer and use it in GitHub Desktop.
// CONFIGURATION CONSTANTS
const REPO: &str = "gtk-rs/gtk4-rs";
const PACKAGE_ID: &str = "UGFja2FnZS0zMjE5MzIyNDY4";
const START_THREASHHOLD: u32 = 5;
// INTERNAL CONSTANTS
const GITHUB_URL: &str = "https://github.com/";
const API_PATH: &str = "/network/dependents?package_id=";
fn populate_list(repos: &mut Vec<String>, url: String) {
eprintln!("Analyzing url: {url}");
let response = reqwest::blocking::get(url).unwrap().text().unwrap();
let lines: Vec<String> = response
.split('\n')
.map(|line| line.trim().to_string())
.filter(|line| !line.is_empty())
.collect();
let mut state = 0;
let mut repo_namespace = String::new();
let mut repo_name = String::new();
for line in lines {
match state {
0 => {
if line.contains("data-test-id=\"dg-repo-pkg-dependent\"") {
state = 1;
} else if line.contains(">Next</a>") {
let url = line
.split('"')
.find(|s| s.starts_with("https://") && s.contains("dependents_after="))
.unwrap()
.to_string();
populate_list(repos, url);
}
}
1 => {
if line.starts_with("<a") {
repo_namespace = line
.split('>')
.nth(1)
.unwrap()
.trim_end_matches("</a")
.to_string();
state = 2;
}
}
2 => {
if line.starts_with("<a") {
repo_name = line
.split('>')
.nth(1)
.unwrap()
.trim_end_matches("</a")
.to_string();
state = 3;
}
}
3 => {
if !line.starts_with('<') {
let stars: u32 = line.replace(',', "").parse().unwrap();
if stars >= START_THREASHHOLD {
repos.push(format!("{repo_namespace}/{repo_name} -> {stars}"));
}
state = 0;
}
}
_ => unreachable!(),
}
}
}
fn main() {
let mut repos = Vec::new();
let url = format!("{GITHUB_URL}{REPO}{API_PATH}{PACKAGE_ID}");
populate_list(&mut repos, url);
repos.sort();
repos.dedup();
let length = repos.len();
for repo in repos {
println!("{repo}");
}
println!("Total repos: {length}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment