Signed-off-by: Ken Swenson <flat@esoteric.moe>
---
This is untested as I cannot get the bot to run on my computer. I believe it to be sound however.
Please test and let me know if changes are needed.
src/comic.rs | 2 +-
src/theme.rs | 14 +++++++-------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/comic.rs b/src/comic.rs
index 8572b72..24a5fec 100644
--- a/src/comic.rs
+++ b/src/comic.rs
@@ -101,7 +101,7 @@ impl ComicEmbed {
));
self.0.url = Some(format!(
- "https://garfield.com/comic/{}/{}/{}",
+ "https://gocomics.com/garfield/{}/{:02}/{:02}",
date.year(),
date.month(),
date.day()
diff --git a/src/theme.rs b/src/theme.rs
index 0af270f..e441590 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -1,4 +1,4 @@
-const COMICS_PER_PAGE: u64 = 6;
+const COMICS_PER_PAGE: u64 = 10;
use regex::Regex;
use reqwest::Client as ReqwestClient;
@@ -16,9 +16,9 @@ pub struct ThemeClient {
impl ThemeClient {
pub fn new_rwc(rwc: ReqwestClient) -> GarfieldResult<Self> {
- let count_re = Regex::new(r#"<span class="pull-right">(?:\d+) of (\d+)</span>"#)?;
+ let count_re = Regex::new(r#"(\d.*) Results for Garfield"#)?;
let comic_re = Regex::new(
- r#"src="https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/[0-9]{4}/([0-9]{4}-[0-9]{2}-[0-9]{2}).gif"#,
+ r#"src="<a itemprop='image' class=\"\" href=\"/garfield/([0-9]+/[0-9]+/[0-9]+)""#,
)?;
Ok(Self {
rwc,
@@ -29,7 +29,7 @@ impl ThemeClient {
async fn get_count(&self, theme: &str) -> GarfieldResult<Option<u64>> {
let url =
- reqwest::Url::parse_with_params("https://garfield.com/comic", &[("keywords", theme)])?;
+ reqwest::Url::parse_with_params("https://www.gocomics.com/search/full_results", &[("terms", theme), ("category", "comic"), ("short_name", "garfield"), ("sort", "date_desc")])?;
let page = self
.rwc
@@ -54,8 +54,8 @@ impl ThemeClient {
) -> GarfieldResult<Option<String>> {
let page = n / COMICS_PER_PAGE;
let url = reqwest::Url::parse_with_params(
- "https://garfield.com/comic",
- &[("keywords", theme), ("page", &format!("{}", page))],
+ "https://www.gocomics.com/search/full_results",
+ &[("category", "comic"), ("short_name", "garfield"), ("sort", "date_desc"), ("terms", theme), ("page", &format!("{}", page))],
)?;
let text = self
.rwc
@@ -73,7 +73,7 @@ impl ThemeClient {
let mut rng = rand::thread_rng();
match cap.choose(&mut rng) {
- Some(c) => Ok(Some(c[1].to_string())),
+ Some(c) => Ok(Some(c[1].to_string().replace("/", "-"))),
None => Ok(None),
}
}
--
2.27.0
This is where the program hangs:
> let comic_re = Regex::new(
> - r#"src="https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/[0-9]{4}/([0-9]{4}-[0-9]{2}-[0-9]{2}).gif"#,
> + r#"src="<a itemprop='image' class=\"\" href=\"/garfield/([0-9]+/[0-9]+/[0-9]+)""#,
> )?;
I am not sure why `async_main` is not correctly terminated. The proper
regex would be something along the lines of:
> r#"src="<a itemprop='image' class="" href="/garfield/([0-9]+/[0-9]+/[0-9]+)""#,
But changing it to that does not make it work.
On Wed, 01 Jul 2020 01:15:52 +0200,
Ken Swenson wrote:
> @@ -16,9 +16,9 @@ pub struct ThemeClient {
>
> impl ThemeClient {
> pub fn new_rwc(rwc: ReqwestClient) -> GarfieldResult<Self> {
> - let count_re = Regex::new(r#"<span class="pull-right">(?:\d+) of (\d+)</span>"#)?;
> + let count_re = Regex::new(r#"(\d.*) Results for Garfield"#)?;
> let comic_re = Regex::new(
> - r#"src="https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/[0-9]{4}/([0-9]{4}-[0-9]{2}-[0-9]{2}).gif"#,
> + r#"src="<a itemprop='image' class=\"\" href=\"/garfield/([0-9]+/[0-9]+/[0-9]+)""#,
> )?;
> Ok(Self {
> rwc,
The program hangs on the second regex, I am not sure why it does not
terminate async_main.
This would be the correct regex for the above:
r#"src="<a itemprop='image' class="" href="/garfield/([0-9]+/[0-9]+/[0-9]+)""#,
Though it does not seem to find what is needed.
Valdemar Erk.
I've fixed the hang but it seems the patch doesn't work as intended.
Debugging now.
On 7/1/20 6:19 PM, Valdemar Erk wrote:
> On Wed, 01 Jul 2020 01:15:52 +0200,
> Ken Swenson wrote:
>> @@ -16,9 +16,9 @@ pub struct ThemeClient {
>>
>> impl ThemeClient {
>> pub fn new_rwc(rwc: ReqwestClient) -> GarfieldResult<Self> {
>> - let count_re = Regex::new(r#"<span class="pull-right">(?:\d+) of (\d+)</span>"#)?;
>> + let count_re = Regex::new(r#"(\d.*) Results for Garfield"#)?;
>> let comic_re = Regex::new(
>> - r#"src="https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/[0-9]{4}/([0-9]{4}-[0-9]{2}-[0-9]{2}).gif"#,
>> + r#"src="<a itemprop='image' class=\"\" href=\"/garfield/([0-9]+/[0-9]+/[0-9]+)""#,
>> )?;
>> Ok(Self {
>> rwc,
> The program hangs on the second regex, I am not sure why it does not
> terminate async_main.
>
> This would be the correct regex for the above:
> r#"src="<a itemprop='image' class="" href="/garfield/([0-9]+/[0-9]+/[0-9]+)""#,
> Though it does not seem to find what is needed.
>
> Valdemar Erk.
>