kraftbj/beer-slurper

Add cron

kraftbj opened this issue · 13 comments

For importing latest checkin, shouldn't need to run a wp cli eval command :)

Does this work?

@khurtwilliams In what sense? It generally does and powers https://kraft.beer . I'm going to close this in favor of the settings UI issue.

The lacking piece is you need to manually fire this function to kick things off: https://github.com/kraftbj/beer-slurper/blob/master/beer-slurper.php#L71

e.g. once you set the Untappd creds in your wp-config.php (I think the settings UI works if you don't want to save it in code, but I don't remember off-hand), you need to fire off `bs_start_import( 'kraft' ); to kick things off.

To stay within Untappd's API limits, it will load 25 checkins an hour each hour until catching up with all of your checkins.

Hi, @kraftbj . I am not trying to be difficult. I'm not understanding.

  1. Install plugin and activate. Complete.
  2. run bs_start_import( $user ) somehow. <--- I guess I don't know how to do that.

Of course! I don't think you're being difficult; the plugin works, but isn't polished and why I never submitted it to the repo.

Presuming you have Untappd API creds saved (via https://untappd.com/api ), you do need to run that function.

If you have SSH access and WP CLI installed, you can do wp eval 'bs_start_import( "kraft" );' (replacing your Untappd user name).

Thanks for giving it a spin with the rough edge. You're the first person to seriously ask about using it , so never got around to making it easy for someone else to get things started. If you're still having trouble, I can try to give it some time to flesh out this piece soon.

I would check out the cron listing with something like WP-Crontrol. It runs every hour, pulling 25 latest checkins (only 25 since most requests can take 2 API calls and the default limit is 100/hour. one for the beer, one for the brewery if it is new. If it is a subsidiary of another brewery, it will pull that one too).

I've ran into a few random API issues that can cause breakage that I haven't put in a robust way around--one case was a beer that brewery was listed as a subsidiary of a brewery that Untappd had "closed" and internally redirect to the original brewery I was seeking. My code doesn't account for what to do in a loop situation like that.

Granted, that happened only one in over 2,000 check-ins for me.

In that case, I adjusted the beer_slurper_{untapped user name}_since option to go to the next beer based on checking out the untappd check-in that broke it.

Unfortunately, it doesn't seem like external API users are a big deal to Untappd so not sure how to get hiccups like that cleaned up within their data.

Ok. Installed WP CLI. I had never used that before. Ran

sudo -u www-data -- wp eval 'bs_start_import( "khurtwilliams" );'

no feedback from CLI so assumed no issues. But ... I don't see any imports.

screen shot 2018-08-18 at 10 46 42 am

Using WP-Crontrol or something like that, if there a cron job for the slurper that includes your user name? That would be enough to kick it off, but it would only import 24 beers an hour.

It's importing ZERO beers. I just checked into two ales and ran wp eval 'bs_start_import( "khurtwilliams" );' several times. Bupkis.

I guess I'll install WP-Control now.

Wait .. I just realized I have no idea why I need to use WP Crontrol.

Successfully added the cron schedule bs_start_import( "khurtwilliams" );

Heh! It works. https://islandinthenet.com/beers/wildcard-brewing-co-crowd-pleaser/ but I don't like the format of the post.

Nice!

I'm using a modified version of Cubic ( https://wordpress.org/themes/cubic/ ) that added a little bit to force the beer post type to be used for the home page via functions.php

function beer_change_the_homepage( $query ) {
	if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_type', 'beerlog_beer' );
    }
}
add_action( 'pre_get_posts', 'beer_change_the_homepage' );

I can't say I'm happy with my format either, but as a place to see what beers I've had and all pictures I've submitted of that beer, it works well enough.