bacons your timeline
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

require 'httparty'
require 'http'
require 'http/request'
$instance_url = ARGV[0]
$bearer_token = ARGV[1]
$text = File.readlines("text.txt")
$pics = (Dir.entries("pics") - %w[.. . .DS_Store]).sort()
def upload_media
headers = {"Authorization": "Bearer #{$bearer_token}"}
file = File.open("pics/"+$pics[$i])
file = HTTP::FormData::File.new(file)
body = {file: file}
response = HTTP.headers(headers).public_send(:post,
"#{$instance_url}/api/v1/media", form: body)
JSON.parse(response.body.to_s)["type"]
$id = JSON.parse(response.body)["id"]
$media = [$id]
end
def create_status(t)
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer #{$bearer_token}"
}
body = {}
body["status"] = t
body["media_ids"] = $media
puts $id
HTTParty.post("#{$instance_url}/api/v1/statuses",
body: JSON.dump(body), headers: headers)
end
$i = 0
$text.each do |t|
puts t
upload_media
create_status(t)
$i +=1
sleep(3)
end