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
Conversation
Because: + #24 This commit: + Add meetup.rb script + HTTParty meetup api + Parse data with Jekyll + Option to archive files
Past events: |
response = HTTParty.get(base_uri) | ||
body = JSON.parse(response.body) | ||
|
||
mu = body["results"][0] |
There was a problem hiding this comment.
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 :)
Need gems added to Gemfile:
As a note to @philtr
replaced with actual API key from https://secure.meetup.com/meetup_api/key/ One other comment, but otherwise, LGTM |
There was a problem hiding this 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:
- 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:
- 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) |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😎
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
@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 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. |
@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. 😄 |
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 👦 👶 👶 . |
Oh yes, and I forgot, here is the official library that Jekyll uses under the hood for their commands: https://github.com/jekyll/mercenary |
This is true. 👶 No joke. This script is actually fun little project whenever I have sometime at night when I am watching the 👶 😄 |
@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 Sicktastic~ Glad you found a solution! |
Because:
This commit: