|
1 |
| -""" |
2 |
| -a simple terminal program to find new about certain topic by web scraping site. |
3 |
| -site used : |
4 |
| -1. Times of India, |
5 |
| - link : https://timesofindia.indiatimes.com/india/ |
6 |
| -2. India's Today, |
7 |
| - link : https://www.indiatoday.in/topic/ |
8 |
| -""" |
9 |
| - |
10 |
| -import requests |
11 |
| -from bs4 import BeautifulSoup |
12 |
| -import webbrowser |
13 |
| -import time |
14 |
| - |
15 |
| - |
16 |
| -def Times_of_India(userInput, ua): |
17 |
| - bold_start = "\033[1m" |
18 |
| - bold_end = "\033[0m" |
19 |
| - |
20 |
| - url = "https://timesofindia.indiatimes.com/india/" |
21 |
| - url += userInput |
22 |
| - |
23 |
| - res = requests.post(url, headers=ua) |
24 |
| - soup = BeautifulSoup(res.content, "html.parser") |
25 |
| - data = soup.find_all(class_="w_tle") |
26 |
| - |
27 |
| - if len(data) > 0: |
28 |
| - print("News available :", "\N{slightly smiling face}") |
29 |
| - if len(data) == 0: |
30 |
| - return 0 |
31 |
| - |
32 |
| - for item in range(len(data)): |
33 |
| - print(bold_start, "\033[1;32;40m \nNEWS : ", item + 1, bold_end, end=" ") |
34 |
| - data1 = data[item].find("a") |
35 |
| - print(bold_start, data1.get_text(), bold_end) |
36 |
| - |
37 |
| - bol = input("For more details ->(y) (y/n) :: ") |
38 |
| - if bol == "y": |
39 |
| - url += data1.get("href") |
40 |
| - print("%s" % url) |
41 |
| - |
42 |
| - webbrowser.open(url) |
43 |
| - |
44 |
| - return len(data) |
45 |
| - |
46 |
| - |
47 |
| -def india_today(userInput, ua): |
48 |
| - bold_start = "\033[1m" |
49 |
| - bold_end = "\033[0m" |
50 |
| - |
51 |
| - url = "https://www.indiatoday.in/topic/" |
52 |
| - url += userInput |
53 |
| - |
54 |
| - res = requests.get(url, headers=ua) |
55 |
| - soup = BeautifulSoup(res.content, "html.parser") |
56 |
| - data = soup.find_all(class_="field-content") |
57 |
| - |
58 |
| - if len(data) > 0: |
59 |
| - print("\nNews available : ", "\N{slightly smiling face}") |
60 |
| - k = 0 |
61 |
| - for i in range(len(data)): |
62 |
| - data1 = data[i].find_all("a") |
63 |
| - for j in range(len(data1)): |
64 |
| - print(bold_start, "\033[1;32;40m\nNEWS ", k + 1, bold_end, end=" : ") |
65 |
| - k += 1 |
66 |
| - print(bold_start, data1[j].get_text(), bold_end) |
67 |
| - bol = input("\nFor more details ->(y) (y/n) :: ") |
68 |
| - if bol == "y" or bol == "Y": |
69 |
| - data2 = data[i].find("a") |
70 |
| - url = data2.get("href") |
71 |
| - webbrowser.open(url) |
72 |
| - |
73 |
| - return len(data) |
| 1 | +def hello_world(): |
| 2 | + """ |
| 3 | + Prints a greeting message. |
| 4 | + """ |
| 5 | + print("Hello, world!") |
74 | 6 |
|
75 | 7 |
|
76 | 8 | if __name__ == "__main__":
|
77 |
| - import doctest |
78 |
| - |
79 |
| - doctest.testmod() |
80 |
| - bold_start = "\033[1m" |
81 |
| - bold_end = "\033[0m" |
82 |
| - print("\033[5;31;40m") |
83 |
| - print( |
84 |
| - bold_start, |
85 |
| - " HERE YOU WILL GET ALL THE NEWS JUST IN ONE SEARCH ", |
86 |
| - bold_end, |
87 |
| - ) |
88 |
| - print("\n") |
89 |
| - localtime = time.asctime(time.localtime(time.time())) |
90 |
| - print(bold_start, localtime, bold_end) |
91 |
| - |
92 |
| - ua = { |
93 |
| - "UserAgent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0" |
94 |
| - } |
95 |
| - print( |
96 |
| - bold_start, |
97 |
| - "\n\033[1;35;40m Search any news (state , city ,Country , AnyThings etc) : ", |
98 |
| - bold_end, |
99 |
| - end=" ", |
100 |
| - ) |
101 |
| - |
102 |
| - userInput = input() |
103 |
| - |
104 |
| - print(bold_start, "\033[1;33;40m \n") |
105 |
| - print("Which news channel data would you prefer") |
106 |
| - print("1. Times of india") |
107 |
| - print("2. India's Today", bold_end) |
108 |
| - |
109 |
| - say = int(input()) |
110 |
| - |
111 |
| - if say == 1: |
112 |
| - length = Times_of_India(userInput, ua) |
113 |
| - if length == 0: |
114 |
| - print("Sorry Here No News Available", "\N{expressionless face}") |
115 |
| - print("\n") |
116 |
| - print( |
117 |
| - "Would you like to go for India's Today (y/n):: ", |
118 |
| - "\N{thinking face}", |
119 |
| - end=" ", |
120 |
| - ) |
121 |
| - speak = input() |
122 |
| - if speak == "y": |
123 |
| - length = india_today(userInput, ua) |
124 |
| - if length == 0: |
125 |
| - print("Sorry No news", "\N{expressionless face}") |
126 |
| - else: |
127 |
| - print("\nThank you", "\U0001f600") |
128 |
| - |
129 |
| - elif say == 2: |
130 |
| - length = india_today(userInput, ua) |
131 |
| - |
132 |
| - if length == 0: |
133 |
| - print("Sorry No news") |
134 |
| - else: |
135 |
| - print("\nThank you", "\U0001f600") |
136 |
| - else: |
137 |
| - print("Sorry", "\N{expressionless face}") |
| 9 | + hello_world() |
0 commit comments