🔥 移除建構其他版本

This commit is contained in:
tasi788 2023-06-18 00:59:44 +08:00
parent 98eed3c588
commit d8027accb9
6 changed files with 0 additions and 1426 deletions

1217
AutoBuild/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +0,0 @@
[package]
name = "AutoBuild"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
fancy-regex = "0.10.0"
reqwest = { version = "0.11.11", features = ["blocking", "json"] }
tokio = { version = "1", features = ["full"] }
time = "0.3.14"
chrono = "0.4.22"
[[bin]]
name = "AutoBuild"
path = "main.rs"

View File

@ -1,5 +0,0 @@
module autobuild
go 1.18
require github.com/thoas/go-funk v0.9.2 // indirect

View File

@ -1,8 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/thoas/go-funk v0.9.2 h1:oKlNYv0AY5nyf9g+/GhMgS/UO2ces0QRdPKwkhY3VCk=
github.com/thoas/go-funk v0.9.2/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -1,62 +0,0 @@
package main
import (
"log"
"reflect"
"time"
)
type FilterList struct {
abp []string
hosts []string
}
type HEAD struct {
abp string
hosts string
}
func main() {
filterlist := &FilterList{
[]string{"experimental.txt", "filter.txt"},
[]string{"hosts.txt", "nofarm_hosts.txt"}}
heads := HEAD{
abp: "[Adblock Plus]\n" +
"! Title: LowTechFilter {name}\n" +
"! Version: {version}\n" +
"! Expires: 1 hour\n" +
"! Homepage: https://t.me/AdBlock_TW\n" +
"! ----------------------------------------------------------------------\n",
hosts: "! FutaHosts\n" +
"! LowTechFilter {name}\n" +
"! URL: <https://github.com/FutaGuard/LowTechFilter>\n" +
"! Version: {version}\n" +
"! --------------------------------------------------\n",
}
url := "https://filter.futa.gg/"
log.Println(url)
log.Println(heads)
location, _ := time.LoadLocation("Asia/Taipei")
now := time.Now().In(location)
log.Println(now)
//fields := reflect.VisibleFields(reflect.TypeOf(filterlist))
v := reflect.ValueOf(filterlist).Elem()
log.Println(v.FieldByName("abp").s)
//for _, field := range fields {
// data := reflect.Indirect(v).FieldByName(field.Name)
// log.Println(data)
//}
log.Println(v)
menu := map[string][]string{
"abp": {"experimental.txt", "filter.txt"},
"hosts": {"hosts.txt", "nofarm_hosts.txt"},
}
for category, data := range menu {
log.Println(category, data)
}
//log.Println(menu)
}

View File

@ -1,117 +0,0 @@
extern crate chrono;
extern crate fancy_regex;
extern crate reqwest;
use chrono::{NaiveDate, Utc};
use fancy_regex::{Captures, Regex};
use std::collections::HashMap;
// use std::fmt::{Debug, Write};
use std::any::type_name;
use std::fs::File;
use std::io::prelude::*;
use std::io::Write;
use std::path::Path;
// use std::fmt::format;
fn type_of<T>(_: T) -> &'static str {
type_name::<T>()
}
fn main() {
let mut filterlist = HashMap::new();
// let mut head = HashMap::new();
filterlist.insert(String::from("abp"), ["experimental.txt", "filter.txt"]);
filterlist.insert(String::from("hosts"), ["hosts.txt", "nofarm_hosts.txt"]);
let _url: &str = "https://filter.futa.gg/";
let now: chrono::DateTime<Utc> = Utc::now();
for category in filterlist {
for text in category.1 {
let mut resp = reqwest::blocking::get(_url.to_owned() + text).unwrap();
if resp.status().is_success() {
} else {
panic!("Something else happened. Status: {:?}", resp.status());
}
let resp = resp.text().unwrap();
let re = Regex::new(r"(?<=Version: )(\d+\.\d+\.)(\d+)").unwrap();
let captures = re.captures(&resp).unwrap();
let mut version: (&str, &str) = match captures {
None => ("2017.0929.", "1"),
_ => (
captures.as_ref().unwrap().get(1).unwrap().as_str(),
captures.as_ref().unwrap().get(2).unwrap().as_str(),
),
};
// "1983 Apr 13 12:09:14.274 +0000", "%Y %b %d %H:%M:%S%.3f %z"
let dt = NaiveDate::parse_from_str(version.0, "%Y.%m%d.").unwrap();
let today = now.date_naive();
let mut newversion = now.format("%Y.%m%d.").to_string().to_owned();
if dt != today {
newversion.push_str("1");
// println!("not today {:?}", newversion);
} else {
let index = version.1.to_string().parse::<i32>().unwrap() + 1;
newversion.push_str(&index.to_string());
}
let mut name: Vec<&str> = text.split(".").collect();
let name = name[0];
let mut output = match category.0.as_str() {
"hosts" => {
format!(
"! FutaHosts\n\
! LowTechFilter {name}\n\
! URL: <https://github.com/FutaGuard/LowTechFilter>\n\
! Version: {version}\n\
! --------------------------------------------------\n",
name = name,
version = newversion
)
}
"abp" => {
format!(
"[Adblock Plus]\n\
! Title: LowTechFilter {name}\n\
! Version: {version}\n\
! Expires: 1 hour\n\
! Homepage: https://t.me/AdBlock_TW\n\
! ----------------------------------------------------------------------\n",
name = name,
version = newversion
)
}
_ => {
continue;
}
};
// open and ready to write
let path = Path::new(text);
let display = path.display(); // Option 用
let mut file = match File::open(&path) {
Err(why) => panic!("couldn't open {}: {:?}", display, why),
Ok(file) => file,
};
let mut reader = String::new();
match file.read_to_string(&mut reader) {
Err(why) => panic!("couldn't read {}: {:?}", display, why),
Ok(..) => println!("{:?}", reader),
};
output.push_str(&reader);
let mut file = match File::create(&path) {
Err(why) => panic!("couldn't create {}: {:?}", display, why),
Ok(file) => file,
};
match file.write_all(output.as_bytes()) {
Err(why) => {
panic!("couldn't write to {}: {:?}", display, why)
},
_ => {},
}
}
}
}