-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.rb
78 lines (63 loc) · 1.87 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# require 'dotenv/load'
require 'nokogiri'
require 'json'
require 'httparty'
require 'nikkou'
require 'twilio-ruby'
@subjects = []
@city_url = "https://studenthub.city.ac.uk/new-students/induction-timetables"
@urls = [ @url1 = @city_url,
@url2 = "#{@city_url}?p=17",
@url3 = "#{@city_url}?p=33",
@url4 = "#{@city_url}?p=49",
@url5 = "#{@city_url}?p=65"
]
@message = ""
@subj_total = ""
def main
@urls.each do |url|
parser(url)
end
printer
end
private
def parser(url)
unparsed_page = HTTParty.get(url)
parsed_page = Nokogiri::HTML(unparsed_page)
@subj_total = parsed_page.css('div.induction-timetable-finder__results__count').text.slice!(0..1)
parsed_page.css('div.induction-timetable-finder h2').text_includes('Journalism').map do |subject|
@subjects << subject.text
end
end
def printer
# count is being updated manually and accordingly after each new sms, listing how many new courses listed
count = 5
journalism_subjects = @subjects.uniq
@message = "There are #{journalism_subjects.length} journalism subjects listed: #{journalism_subjects}"
puts ""
puts "Time: #{Time.now.utc.iso8601}"
puts "-----------------------------"
journalism_subjects.each do |subject|
puts subject
end
puts "-----------------------------"
puts "The page says there are #{@subj_total} courses listed"
if journalism_subjects.length > count
sms
# need to update count once sms has been sent, so program doesn't continue to send sms's
# best to do this with db - sqlite or postgres
count = journalism_subjects
end
end
# twilio sms code - add your own credentials
def sms
account_sid = <your account sid>
auth_token = <your auth token>
client = Twilio::REST::Client.new(account_sid, auth_token)
client.messages.create(
from: <twilio number>,
to: <your number>,
body: @message
)
end
main