Run the contents of a second file in the first
source link: https://www.codesd.com/item/run-the-contents-of-a-second-file-in-the-first.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Run the contents of a second file in the first
I have a question, as I can edit this code to "twit" in a ruby file to send...
would be better that everything can be done from a file... but I can not do it :(
From already thank you very much! and this is my first post, if I mistake apology. I always read but now I can not find a twitter for ruby updated :(
require 'Twitter'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
client = Twitter::REST::Client.new do |config|
config.consumer_key = "xxxx"
config.consumer_secret = "xxxx"
config.access_token = "xxxx"
config.access_token_secret = "xxxx"
end
file = File.open("scrapy.rb")
ary = []
i = 0
file.each_line do |line|
ary[i] = line.chomp
i += 1
end
file.close
j = 0
i.times do
client.update("#{ary[j]}")
j += 1
sleep 10
end
My scrapy
require 'nokogiri'
require 'open-uri'
page = Nokogiri::XML(open('xxxxxxxxxxxx'))
eventos= page.xpath("//item")
eventos.each do |e|
ubicacion = e.xpath "title"
magnitud = e.xpath "emsc:magnitude"
horaUTC = e.xpath("emsc:time").text.split(" ",2).last
depth = e.xpath "emsc:depth"
link = e.xpath "guid"
puts [ubicacion, magnitud, horaUTC, depth, link].join "|"
end
Instead of
file = File.open("scrapy.rb")
simply require or load the other file
load 'scrapy'
Even better, you can convert the content of scrapy
in a function, require the file once at the top of the first file, and call the function where you need it.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK