Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MeetUp import automation 🔄 #27

Closed
wants to merge 1 commit into from
Closed

Add MeetUp import automation 🔄 #27

wants to merge 1 commit into from

Conversation

sicktastic
Copy link

Because:

This commit:

  • Add meetup.rb script
  • HTTParty meetup api
  • Parse data with Jekyll
  • Option to archive files

Because:

+ #24

This commit:

+ Add meetup.rb script
+ HTTParty meetup api
+ Parse data with Jekyll
+ Option to archive files
@sicktastic
Copy link
Author

Past events: https://api.meetup.com/2/events?key=#{meetup_api_key}&group_urlname=#{meetup_group_url}&sign=true&status=past

response = HTTParty.get(base_uri)
body = JSON.parse(response.body)

mu = body["results"][0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should iterate over the results? Maybe someday we will actually plan multiple events in the future :)

@joshuawscott
Copy link
Member

joshuawscott commented Jan 21, 2017

Need gems added to Gemfile:

  • HTTParty
  • colorize
  • dotenv

As a note to @philtr
.env file should look like:

MEETUP_API_KEY='abcdef1234567890'

replaced with actual API key from https://secure.meetup.com/meetup_api/key/

One other comment, but otherwise, LGTM

Copy link
Member

@philtr philtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @antwonlee, thank you so much for doing this! I really appreciate the effort put in here to make this process as simple as possible.

This is a fantastic start; however, I have quite a few concerns with this pull request that I would like to address before merging. For most of them, I left comments scattered throughout the code. Here are a few general concerns that I think would make this script really stellar:

  1. Jekyll Command – I mentioned this in Meetup Event importer #24, but I think it would be real slick if we could make this a jekyll command. Doesn't have to be its own repo at this point, take a look at these files on my personal website to see how a command could be implemented as a gem that could eventually be extracted out:
  2. Multiple Events - Like @joshuawscott said, I think it should iterate over all the events returned by the Meetup API, and it should move old events to the _archived_events folder (but not currently upcoming events). Also, it looks like the way it's set up, if there are any events in the _upcoming_events folder already, it won't make it to the logic to create a new event. I don't think that should be what decides what to do.

I'm happy to jump in and help or pair with you on any of this stuff. (Sorry for throwing up on your PR!)

meetup_group_url = "ny-tech"
# meetup_group_url = "RubyFTW-Fort-Worth-Ruby-User-Group"
base_uri = "https://api.meetup.com/2/events?key=#{meetup_api_key}&group_urlname=#{meetup_group_url}&sign=true"
response = HTTParty.get(base_uri)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is all we're using HTTParty for, you could drop the dependency and do this instead:

response = Net::HTTP.get(URI.parse(base_uri))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Dotenv.load
meetup_api_key = ENV["MEETUP_API_KEY"]

meetup_group_url = "ny-tech"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an environment variable as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

puts "No files were archived.".light_blue + " Do you want to create a new post?\n" + @yes_or_no
validate_to_create_new_post
else
puts "Wrong input... Make sure to type 'Y' or 'N' 😎".red
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

@yes_or_no = "[Y]".green + "Yes" + " [N]".red + "No"

def validate_to_archive
answer_to_archive = gets.chomp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it might be possible check to see if the date is in the past instead of asking for user input? Would save a bunch of time, especially if for some reason I haven't run the script in a while and I need to archive a bunch of old meetups.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What date would you prefer to compare it with? Technically, they should all be in the past if the files exist there. Let me know what you are thinking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Well, hopefully there is at least one in the future, right? If I run the script and import an event, then run the script again, there will be one in the future. We could just compare w/ the date in the file name so we don't have to parse the frontmatter.

puts "Wrong input... Make sure to type 'Y' or 'N' 😎".red
end
end
def validate_to_create_new_post
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the function above it are eerily similar. I wonder if you could extract it to something like this instead:

def confirm?
  answer = gets.chomp
  case answer
  when "Y", "y" then true
  when "N", "n" then false
  else
    puts "Wrong input... Make sure to type 'Y' or 'N'  😎".red
  end
end

# ...

if @directory_file_count >= 1
  puts "..."
  archive_post if confirm?
else
  puts "..."
  create_post if confirm?
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way better. Much cleaner for sho.


def create_post
content = "---\nlayout: post\ntitle: #{@title}\nlong_date: #{@long_date}\nlink: #{@link}\ntime: #{@time}\nlocation: #{@location}\nlocation_url: #{@location_url}\nrsvp_url: #{@rsvp_url}\n---\n#{@description}"
new_event = File.new("#{Dir.pwd}/#{@directory}/#{@file_name_date}-#{@title.downcase!.gsub! /\s+/, '-'}.md", "w")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only put dashes in place of spaces, so if you have "Rails & Docker" as your event name, the file name is going to be 2017-09-09-rails-&-docker.md which might cause problems. Maybe try something like this instead?

@title = "Rails & Docker: Extravaganza!"
@title.downcase!.gsub!(/[^[:alnum]]/,"-").squeeze!("-").chomp!("-")
# => "rails-docker-extravaganza"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do you think we should be doing some kind of check to make sure we don't try to import the same Meetup twice? I suspect this script would either error or overwrite the existing file (which may have been previously modified to look nicer on the website).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, more validations the better.

answer_to_archive = gets.chomp
if answer_to_archive === "Y" || answer_to_archive === "y"
puts "Moving files...".light_blue
FileUtils.mv Dir.glob("#{@directory}/*"), @archived_directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moves all the files in _upcoming_events to _archived_events, right? Might cause problems if there is still a future event in _upcoming_events.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as of now all the files go to _archived_events. Even if you iterate through each files in the future, you would probably still need to manually decided since the data is created into Jekyll rather than just parsing the live data from MeetUp. For example, I can think of filtering through status of the event but that will be challenging since you are basically copying and pasting data into Jekyll file oppose to live data. Any thoughts?

@sicktastic
Copy link
Author

@philtr These are great inputs! I am hoping that we have 10 or more MeetUps planned for this script to work. 😄 I am not that familiar with Jekyll as much but running a jekyll something something command seems more clean for sure since you are already working in that ecosystem.

It was a start. I just took a stab at it last night when I was watching my 👶

It will be fun to do some pairing at the MeetUp with other members to get the script you deserve!

I think coding together and code reviews are best way to learn from each other.

@sicktastic
Copy link
Author

@philtr Hey, it was a busy work week. I am looking into this again with your preference of making it a Jekyll command. Do you have any resources where I can read about to see how it can be implemented rather than your sample code? I thought perhaps you already did some since you have the experience. I hardly use Jekyll other than making a simple static pages so don't know much in depth.

I think I actually want this script for myself. 😄

@philtr
Copy link
Member

philtr commented Jan 29, 2017

Hey no worries, there is no rush on this at all 😄

I don't know of any resources except the official documentation, which is not very helpful. I had to stumble through it myself until it finally clicked. I think maybe I have a topic for my first blog post in over 2 years 😆

Like I said, I'd be happy to pair with you on getting it started, but I think we might have difficulties finding a time to do it because 👦 👶 👶 .

@philtr
Copy link
Member

philtr commented Jan 29, 2017

Oh yes, and I forgot, here is the official library that Jekyll uses under the hood for their commands: https://github.com/jekyll/mercenary

@sicktastic
Copy link
Author

This is true. 👶 No joke. This script is actually fun little project whenever I have sometime at night when I am watching the 👶 😄

@philtr
Copy link
Member

philtr commented Aug 17, 2017

@antwonlee Just a heads up that I am closing this PR since #28 added JavaScript Meetup integration, which is honestly probably better, since we won't have to push an update to the website every time we add a new event. I really appreciate the effort you put in here and want to thank you for the time you spent on this!

@philtr philtr closed this Aug 17, 2017
@sicktastic
Copy link
Author

@philtr Sicktastic~ Glad you found a solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants