Skip to content

Updated file writing so it does not fail if there are no query results #8

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions searchtweets/search_tweets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,18 @@ def make_data_request(query, start_time, end_time, since_id, until_id, max_resul

if @write_mode == 'files' #write the file.

#Each 'page' has a start and end time, go get those for generating filename.

filename = ""
#TODO: just pass in first timestamp: results.first['created_at']
filename = get_file_name(query, api_response['data'])

puts "Storing Search API data in file: #{filename}"
File.open("#{@out_box}/#{filename}.json", "w") do |new_file|
new_file.write(api_response.to_json)
if api_response.key?("data")
#Each 'page' has a start and end time, go get those for generating filename.
filename = ""
#TODO: just pass in first timestamp: results.first['created_at']
filename = get_file_name(query, api_response['data'])

puts "Storing Search API data in file: #{filename}"
File.open("#{@out_box}/#{filename}.json", "w") do |new_file|
new_file.write(api_response.to_json)
end
else
puts "No Tweets." if @verbose
end

elsif @write_mode == 'standard_out' #Standard out
Expand Down