mirror of
https://github.com/FutaGuard/LowTechFilter.git
synced 2025-06-21 05:21:02 +08:00
🐛 等待修正讀取檔案問題
This commit is contained in:
parent
f0c1c585f2
commit
b127e0ea5b
97
AutoBuild/Cargo.lock
generated
97
AutoBuild/Cargo.lock
generated
@ -6,8 +6,10 @@ version = 3
|
||||
name = "AutoBuild"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"fancy-regex",
|
||||
"reqwest",
|
||||
"time 0.3.14",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@ -20,6 +22,15 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
@ -77,6 +88,21 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"time 0.1.44",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.3"
|
||||
@ -304,6 +330,20 @@ dependencies = [
|
||||
"tokio-native-tls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "237a0714f28b1ee39ccec0770ccb544eb02c9ef2c82bb096230eefcffa6468b0"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"js-sys",
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.3.0"
|
||||
@ -405,7 +445,7 @@ checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi",
|
||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
@ -427,6 +467,25 @@ dependencies = [
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.13.1"
|
||||
@ -437,6 +496,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.14.0"
|
||||
@ -758,6 +826,27 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi 0.10.0+wasi-snapshot-preview1",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c3f9a28b618c3a6b9251b6908e9c99e04b9e5c02e6581ccbb67d59c34ef7f9b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"num_threads",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
@ -909,6 +998,12 @@ dependencies = [
|
||||
"try-lock",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
|
@ -9,6 +9,8 @@ edition = "2021"
|
||||
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"
|
||||
|
@ -1,28 +1,29 @@
|
||||
extern crate chrono;
|
||||
extern crate fancy_regex;
|
||||
extern crate reqwest;
|
||||
use chrono::{NaiveDate, Utc};
|
||||
use fancy_regex::{Captures, Regex};
|
||||
use reqwest;
|
||||
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();
|
||||
// let mut head = HashMap::new();
|
||||
filterlist.insert(String::from("abp"), ["experimental.txt", "filter.txt"]);
|
||||
filterlist.insert(String::from("hosts"), ["hosts.txt", "nofarm_hosts.txt"]);
|
||||
|
||||
head.insert(String::from("abp"), "[Adblock Plus]\n
|
||||
! Title: LowTechFilter {name}\n
|
||||
! Version: {version}\n
|
||||
! Expires: 1 hour\n
|
||||
! Homepage: https://t.me/AdBlock_TW\n
|
||||
! ----------------------------------------------------------------------\n");
|
||||
head.insert(
|
||||
String::from("hosts"),
|
||||
"! FutaHosts\n\
|
||||
! LowTechFilter {name}\n\
|
||||
! URL: <https://github.com/FutaGuard/LowTechFilter>\n\
|
||||
! Version: {version}\n\
|
||||
! --------------------------------------------------\n",
|
||||
);
|
||||
let _url: &str = "https://filter.futa.gg/";
|
||||
let now: chrono::DateTime<Utc> = Utc::now();
|
||||
|
||||
for category in filterlist {
|
||||
for text in category.1 {
|
||||
@ -43,7 +44,74 @@ fn main() {
|
||||
captures.as_ref().unwrap().get(2).unwrap().as_str(),
|
||||
),
|
||||
};
|
||||
println!("{:?}", version)
|
||||
|
||||
// "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 = String::from("");
|
||||
match category.0.as_str() {
|
||||
"hosts" => {
|
||||
output = format!(
|
||||
"! FutaHosts\n\
|
||||
! LowTechFilter {name}\n\
|
||||
! URL: <https://github.com/FutaGuard/LowTechFilter>\n\
|
||||
! Version: {version}\n\
|
||||
! --------------------------------------------------\n",
|
||||
name = name,
|
||||
version = newversion
|
||||
)
|
||||
}
|
||||
"abp" => {
|
||||
output = 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
|
||||
)
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
// 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),
|
||||
}
|
||||
|
||||
println!("{:?}", file);
|
||||
let mut file = match File::create(&path) {
|
||||
Err(why) => panic!("couldn't create {}: {:?}", display, why),
|
||||
Ok(file) => file,
|
||||
};
|
||||
// match file.write_all(LOREM_IPSUM.as_bytes()) {
|
||||
// Err(why) => {
|
||||
// panic!("couldn't write to {}: {:?}", display, why)
|
||||
// },
|
||||
// _ => {},
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user