Check-in [fb629f170b]
Logged in as anonymous
Overview
Comment:0.2.2: finally regex works
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fb629f170b6a5eaa3ff93464ee8d6cda854fe7369060f400617be69b1b85028c
User & Date: arcade on 2021-11-13 21:50:00.869
Other Links: manifest | tags
Context
2021-11-13
23:16
fix list, add "-" for disabled fields, some reordering check-in: c1e27b74ed user: arcade tags: trunk
21:50
0.2.2: finally regex works check-in: fb629f170b user: arcade tags: trunk
20:37
fix messages, store edit string check-in: 10c25017bb user: arcade tags: trunk
Changes
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
 "derive_builder 0.9.0",
 "quick-xml 0.17.2",
 "reqwest 0.9.24",
]

[[package]]
name = "rsstg"
version = "0.2.1"
dependencies = [
 "anyhow",
 "atom_syndication",
 "chrono",
 "config",
 "futures 0.3.17",
 "futures-util",







|







2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
 "derive_builder 0.9.0",
 "quick-xml 0.17.2",
 "reqwest 0.9.24",
]

[[package]]
name = "rsstg"
version = "0.2.2"
dependencies = [
 "anyhow",
 "atom_syndication",
 "chrono",
 "config",
 "futures 0.3.17",
 "futures-util",
1
2
3
4
5
6
7
8
9
10
[package]
name = "rsstg"
version = "0.2.1"
authors = ["arcade"]
edition = "2018"

[dependencies]
anyhow = "*"
atom_syndication = { version = "*", features = [ "with-serde" ] }
chrono = "*"


|







1
2
3
4
5
6
7
8
9
10
[package]
name = "rsstg"
version = "0.2.2"
authors = ["arcade"]
edition = "2018"

[dependencies]
anyhow = "*"
atom_syndication = { version = "*", features = [ "with-serde" ] }
chrono = "*"
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
				.bind(*id)
				.bind(owner)
				.fetch_one(&mut conn).await
				.with_context(|| format!("Query source:\n{:?}", &self.pool))?;
			drop(conn);
			let channel_id: i64 = row.try_get("channel_id")?;
			let url: &str = row.try_get("url")?;
			/*let url: Cow<'a, str> = match row.try_get("url") {
				Ok(x) => String::from(x).to_owned().into(),
				Err(err) => bail!("Test"),
			};*/
			let iv_hash: Option<&str> = row.try_get("iv_hash")?;
			//let url_re: Option<sedregex::ReplaceCommand> = match row.try_get("url_re")? {
			let url_re = match row.try_get("url_re")? {
				Some(x) => Some(sedregex::ReplaceCommand::new(x)?),
				None => None,
			};
			let destination = match real {
				true => telegram_bot::UserId::new(channel_id),
				false => telegram_bot::UserId::new(row.try_get("owner")?),







<
<
<
<

<







98
99
100
101
102
103
104




105

106
107
108
109
110
111
112
				.bind(*id)
				.bind(owner)
				.fetch_one(&mut conn).await
				.with_context(|| format!("Query source:\n{:?}", &self.pool))?;
			drop(conn);
			let channel_id: i64 = row.try_get("channel_id")?;
			let url: &str = row.try_get("url")?;




			let iv_hash: Option<&str> = row.try_get("iv_hash")?;

			let url_re = match row.try_get("url_re")? {
				Some(x) => Some(sedregex::ReplaceCommand::new(x)?),
				None => None,
			};
			let destination = match real {
				true => telegram_bot::UserId::new(channel_id),
				false => telegram_bot::UserId::new(row.try_get("owner")?),
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
				let exists: bool = row.try_get("exists")?;
				if ! exists {
					if this_fetch == None || *date > this_fetch.unwrap() {
						this_fetch = Some(*date);
					};
					self.tg.send( match iv_hash {
							Some(hash) => telegram_bot::SendMessage::new(destination, format!("<a href=\"https://t.me/iv?url={}&rhash={}\"> </a>{0}", match url_re {
								Some(x) => {
									bail!("Regex hit, result:\n{:#?}", x.execute(url));
									url
								},
								None => url,
							}, hash)),
							None => telegram_bot::SendMessage::new(destination, format!("{}", url)),
						}.parse_mode(telegram_bot::types::ParseMode::Html)).await
						.context("Can't post message:")?;
					sqlx::query("insert into rsstg_post (source_id, posted, url) values ($1, $2, $3);")
						.bind(*id)
						.bind(date)







<
|
<
<
|







155
156
157
158
159
160
161

162


163
164
165
166
167
168
169
170
				let exists: bool = row.try_get("exists")?;
				if ! exists {
					if this_fetch == None || *date > this_fetch.unwrap() {
						this_fetch = Some(*date);
					};
					self.tg.send( match iv_hash {
							Some(hash) => telegram_bot::SendMessage::new(destination, format!("<a href=\"https://t.me/iv?url={}&rhash={}\"> </a>{0}", match url_re {

								Some(ref x) => x.execute(url).to_string(),


								None => url.to_string(),
							}, hash)),
							None => telegram_bot::SendMessage::new(destination, format!("{}", url)),
						}.parse_mode(telegram_bot::types::ParseMode::Html)).await
						.context("Can't post message:")?;
					sqlx::query("insert into rsstg_post (source_id, posted, url) values ($1, $2, $3);")
						.bind(*id)
						.bind(date)
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
			let mut queue = sqlx::query("select source_id, next_fetch, owner from rsstg_order natural left join rsstg_source where next_fetch < now() + interval '1 minute';")
				.fetch_all(&mut conn).await?;
			for row in queue.iter() {
				let source_id: i32 = row.try_get("source_id")?;
				let owner: i64 = row.try_get("owner")?;
				let next_fetch: DateTime<chrono::Local> = row.try_get("next_fetch")?;
				if next_fetch < now {
					//let clone = self.clone();
					//clone.owner_chat(UserId::new(owner));
					let clone = Core {
						owner_chat: telegram_bot::UserId::new(owner),
						..self.clone()
					};
					tokio::spawn(async move {
						if let Err(err) = clone.check(&source_id, owner, true).await {
							if let Err(err) = clone.send(&format!("🛑 {:?}", err), None, None) {







<
<







307
308
309
310
311
312
313


314
315
316
317
318
319
320
			let mut queue = sqlx::query("select source_id, next_fetch, owner from rsstg_order natural left join rsstg_source where next_fetch < now() + interval '1 minute';")
				.fetch_all(&mut conn).await?;
			for row in queue.iter() {
				let source_id: i32 = row.try_get("source_id")?;
				let owner: i64 = row.try_get("owner")?;
				let next_fetch: DateTime<chrono::Local> = row.try_get("next_fetch")?;
				if next_fetch < now {


					let clone = Core {
						owner_chat: telegram_bot::UserId::new(owner),
						..self.clone()
					};
					tokio::spawn(async move {
						if let Err(err) = clone.check(&source_id, owner, true).await {
							if let Err(err) = clone.send(&format!("🛑 {:?}", err), None, None) {