Created
July 30, 2018 12:56
-
-
Save tesths/f4315e5ccaf9710ebadfe88fd7409494 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'httparty' | |
require 'telegram/bot' | |
require 'byebug' | |
def request_ins | |
begin | |
puts "request start at " + Time.now.to_s | |
response = HTTParty.get('https://www.instagram.com/twicetagram/', timeout: 60) | |
rescue HTTParty::Error => e | |
# don´t do anything / whatever | |
puts "HTTParty::Error " + e.to_s | |
sleep(5) | |
requestIns | |
rescue StandardError => e | |
puts "StandardError " + e.to_s | |
sleep(5) | |
requestIns | |
end | |
return response | |
end | |
def check_response | |
response = request_ins | |
if !response.nil? | |
if response.code.between?(400, 600) | |
puts Time.now + response.code.to_s | |
return 0 | |
else | |
puts "response success! response code is " + response.code.to_s | |
regex = %r{(?<=window._sharedData = ).+(?=;</script>)} | |
data = response.scan(regex)[0] | |
begin | |
json = JSON.parse(data) | |
rescue JSON::ParserError | |
puts "JSON::ParserError" | |
sleep(5) | |
request_ins | |
end | |
if json.nil? | |
puts "response nil" | |
return 0 | |
else | |
return json["entry_data"]["ProfilePage"][0] | |
end | |
end | |
else | |
puts "response nil" | |
return 0 | |
end | |
end | |
puts check_response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment