Top Level Namespace

Defined Under Namespace

Modules: DreamTeam Classes: Film

Instance Method Summary collapse

Instance Method Details

#create_table_with_film(path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/DreamTeam/Films/html_films_table.rb', line 3

def create_table_with_film(path)
  erd_str = File.read(File.dirname(__FILE__) + '/films_page.html.erb')
  filmsInformation = get_all_films(get_films_id())
  @films_information = filmsInformation
  renderer = ERB.new(erd_str)
  result = renderer.result(binding)
  File.open(path + "/table_film.html", 'w') do |f|
    f.write(result)
    end
end

#create_table_with_user_games(path, steam_id) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/DreamTeam/Games/html_games_table.rb', line 4

def create_table_with_user_games(path, steam_id)
  erb_str = File.read(File.dirname(__FILE__) + '/games_page.html.erb')

   = get_user_information(steam_id)
  games_information = information_of_games(get_user_games(steam_id))

  @avatar = [:avatar]
  @username = [:username]
  @games_information = games_information
  renderer = ERB.new(erb_str)
  result = renderer.result(binding)

  File.open(path + "/table_game.html", 'w') do |f|
    f.write(result)
  end
end

#get_all_films(text) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/DreamTeam/Films/parsing_films.rb', line 45

def get_all_films(text)

  arr_films = []
  while text.index('}') != nil
    ind_start = 0
    ind_finish = text.index('}')
    dist = ind_finish - ind_start + 1
    arr_films << text[ind_start, dist].gsub(' "', '"')
    text = text.gsub(text[ind_start, dist], '')
  end

  rezult = []
  arr_films.each do |f|
    rezult << Film.new(f)
  end

  rezult
end

#get_films_idObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/DreamTeam/Films/parsing_films.rb', line 32

def get_films_id()
  uri = 'https://imdb-api.com/en/API/Top250Movies/k_uq4za59n'
  doc = Nokogiri::HTML(URI.open(uri))

  text = doc.text.gsub('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
                      "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body><p>', '')
  text = text.gsub('{"items":[', '').gsub(']', '')

  #text = '{"id":"1424411", ":rank":"1", ":title":"title 1", ":year":"1990", ":image":"http:\picture1.com",":crew":"Tom Jon Mike", ":imDbRating":"9.2", ":imDbRatingCount":"8.1"},{"id":"9352791", ":rank":"2", ":title":"title 2", ":year":"2006", ":image":"http:\picture1.com",":crew":"Tom Jon Mike", ":imDbRating":"9.2", ":imDbRatingCount":"8.1"},{"id":"1908543", ":rank":"3", ":title":"title 3", ":year":"2012", ":image":"http:\picture1.com",":crew":"Tom Jon Mike", ":imDbRating":"9.2", ":imDbRatingCount":"8.1"}'
  #text = '{"id":"tt0111161","rank":"1","title":"The Shawshank Redemption","fullTitle":"The Shawshank Redemption (1994)","year":"1994","image":"https://m.media-amazon.com/images/M/MV5BMDFkYTc0MGEtZmNhMC00ZDIzLWFmNTEtODM1ZmRlYWMwMWFmXkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_UX128_CR0,12,128,176_AL_.jpg","crew":"Frank Darabont (dir.), Tim Robbins, Morgan Freeman","imDbRating":"9.2","imDbRatingCount":"2650504"},{"id":"tt0068646","rank":"2","title":"The Godfather","fullTitle":"The Godfather (1972)","year":"1972","image":"https://m.media-amazon.com/images/M/MV5BM2MyNjYxNmUtYTAwNi00MTYxLWJmNWYtYzZlODY3ZTk3OTFlXkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_UX128_CR0,12,128,176_AL_.jpg","crew":"Francis Ford Coppola (dir.), Marlon Brando, Al Pacino","imDbRating":"9.2","imDbRatingCount":"1837317"},{"id":"tt0468569","rank":"3","title":"The Dark Knight","fullTitle":"The Dark Knight (2008)","year":"2008","image":"https://m.media-amazon.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_UX128_CR0,12,128,176_AL_.jpg","crew":"Christopher Nolan (dir.), Christian Bale, Heath Ledger","imDbRating":"9.0","imDbRatingCount":"2622617"},{"id":"tt0071562","rank":"4","title":"The Godfather Part II","fullTitle":"The Godfather Part II (1974)","year":"1974","image":"https://m.media-amazon.com/images/M/MV5BMWMwMGQzZTItY2JlNC00OWZiLWIyMDctNDk2ZDQ2YjRjMWQ0XkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_UX128_CR0,12,128,176_AL_.jpg","crew":"Francis Ford Coppola (dir.), Al Pacino, Robert De Niro","imDbRating":"9.0","imDbRatingCount":"1259016"},{"id":"tt0050083","rank":"5","title":"12 Angry Men","fullTitle":"12 Angry Men (1957)","year":"1957","image":"https://m.media-amazon.com/images/M/MV5BMWU4N2FjNzYtNTVkNC00NzQ0LTg0MjAtYTJlMjFhNGUxZDFmXkEyXkFqcGdeQXVyNjc1NTYyMjg@._V1_UX128_CR0,12,128,176_AL_.jpg","crew":"Sidney Lumet (dir.), Henry Fonda, Lee J. Cobb","imDbRating":"9.0","imDbRatingCount":"782597"}'
  text.gsub('},', '}').gsub('"errorMessage":""}', '')
end

#get_user_games(steam_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/DreamTeam/Games/parsing_games.rb', line 11

def get_user_games(steam_id)
  res = []
  begin
    url = Nokogiri::HTML5(URI.open('https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?steamid=' +
                                     +steam_id + '&key=' + 'FB8E10E3C18DFD06F605ACF4D049866A')).to_s
  rescue
    return res
  end
  arr = url.split(',')
  last_id = ''
  arr.each do |a|
    id = a.match(/"appid":(?<id>.*)/)
    if !id.nil?
      last_id = id[:id]
    else
      time = a.match(/"playtime_forever":(?<time>.*)/)
      if !time.nil?
        res.push({ id: last_id, time: time[:time] })
      end
    end
  end
  res
end

#get_user_information(steam_id) ⇒ Object



4
5
6
7
8
9
# File 'lib/DreamTeam/Games/parsing_games.rb', line 4

def get_user_information(steam_id)
  url = Nokogiri::HTML5(URI.open('https://steamcommunity.com/profiles/' + steam_id + '/?xml=1')).to_s
  username = url[/<steamid><!--\[CDATA\[(?<username>.*)\]\]--><\/steamid>/, 1]
  avatar = url[/<avataricon><!--\[CDATA\[(?<avatar>.*)\]\]--><\/avataricon>/, 1]
  { username: username, avatar: avatar }
end

#information_of_games(games_id) ⇒ Object



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
# File 'lib/DreamTeam/Games/parsing_games.rb', line 35

def information_of_games(games_id)
  res = []
  games_id.each do |g|
    begin
      url = Nokogiri::HTML5(URI.open('https://store.steampowered.com/api/appdetails/?appids=' + g[:id])).to_s
    rescue
      next
    end
    name = url[/"name":"(?<name>.*)","steam_/, 1]
    time = g[:time]
    date = url[/date":"(?<date>.*)"},"su/, 1]
    price = url[/nal_formatted":"(?<price>.*) pуб\."},"pac/, 1]
    if price == nil
      price = url[/nal_formatted":"(?<price>.*)"},"pac/, 1]
    else
      price += ' rub'
    end
    developers = url[/"developers":\[(?<developers>.*)\],"publishers"/, 1]
    if developers != nil
      developers = developers.delete "\""
    end
    recommendations = url[/tions":{"total":(?<recommendations>\d*)/, 1]
    desc = url[/t_description":"(?<desc>.*)","sup/, 1]
    img = url[/"header_image":"(?<img>.*)","website"/, 1]

    res.push({ name: name, time: time, date: date, price: price, developers: developers,
               recommendations: recommendations, desc: desc, img: img })
  end
  res
end