Skip to content

Commit 9940d85

Browse files
committed
Version 2.0 added
1 parent 43ef6fa commit 9940d85

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

News Fetcher/__init__.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from newsme.nm import NewsMe
22
from flask import Flask, redirect, url_for, request, render_template
33
import requests
4+
import re
45

56
app = Flask(__name__)
67

@@ -11,17 +12,32 @@ def index():
1112
@app.route('/search', methods =['POST'])
1213
def search():
1314
search = request.form['search']
15+
msg=""
1416
if search == "":
1517
return render_template('index.html')
1618
else:
17-
N = NewsMe(search)
18-
headline = []
19-
links = []
20-
for i in N.headlines():
21-
headline.append(i[0])
22-
links.append(i[1])
23-
no = len(headline)
24-
return render_template('search.html',headline=headline,links=links,search=search,no=no)
19+
match = re.search(r'(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)',search)
20+
if match:
21+
N = NewsMe(search)
22+
headline = []
23+
links = []
24+
for i in N.headlines():
25+
headline.append(i[0])
26+
links.append(i[1])
27+
28+
new_match = re.search(r'(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)',links[1])
29+
if new_match:
30+
new=""
31+
else:
32+
if search[-1]== "/":
33+
new=search[0:-1]
34+
else:
35+
new=search
36+
37+
return render_template('search.html',headline=headline,links=links,search=search,new=new)
38+
else:
39+
msg = "Enter valid Url"
40+
return render_template("index.html",msg=msg)
2541

2642
if __name__ == '__main__':
2743
app.run(debug = True)

News Fetcher/templates/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>NewsME</title>
5+
<title>News Fetcher</title>
66
<!--JS links -->
77
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
88
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>
@@ -21,16 +21,17 @@
2121
<div class="container">
2222
<div class="jumbotron">
2323
<div class="content-wrap text-center">
24-
<h1>NewsME<br><p>Find any current news easily!!</p></h1>
24+
<h1>News Fetcher<br><p>Find any current news easily!!</p></h1>
2525
<form method="POST" action="/search">
26-
<input id="tags" type="url" name="search" placeholder="https://example.com"autofocus="on" list="defaultURLs">
26+
<input id="tags" type="text" name="search" placeholder="https://example.com"autofocus="on" list="defaultURLs">
2727
<datalist id="defaultURLs">
2828
<option value="https://timesofindia.indiatimes.com/" label="TimesOfIndia">
2929
<option value="https://www.tribuneindia.com/" label="TribuneIndia">
3030
</datalist>
3131
<br>
3232
<button id="getResult" class="btn btn-default"><i class="fa fa-search"></i>Search</button>
3333
</form>
34+
<h3 style="color: white;">{{msg}}</h3>
3435
</div>
3536
<div class="wrap text-center">
3637
<ul>

News Fetcher/templates/search.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class ="wrap text-center">
66
<ul>
77
{% for i in range(20) %}
8-
<a style="font-size: 21px;" target="_blank" href="{{search[0:-1]+links[i]}}"><strong>
8+
<a style="font-size: 21px;" target="_blank" href="{{new+links[i]}}"><strong>
99
{{headline[i]}}</strong><br></a>
1010
{% endfor %}
1111
</ul>

0 commit comments

Comments
 (0)