Skip to content

Commit 2cd36d6

Browse files
committed
new
0 parents  commit 2cd36d6

20 files changed

+302
-0
lines changed

db.sqlite3

Whitespace-only changes.

jan/__init__.py

Whitespace-only changes.
132 Bytes
Binary file not shown.
2.2 KB
Binary file not shown.

jan/__pycache__/urls.cpython-37.pyc

978 Bytes
Binary file not shown.

jan/__pycache__/wsgi.cpython-37.pyc

527 Bytes
Binary file not shown.

jan/settings.py

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
"""
2+
Django settings for jan project.
3+
4+
Generated by 'django-admin startproject' using Django 2.1.5.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.1/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = '$(d%gxdj$a%yarazr-wz^155_6_#y2tbad5xjsv@orn7*%ed42'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
]
41+
42+
MIDDLEWARE = [
43+
'django.middleware.security.SecurityMiddleware',
44+
'django.contrib.sessions.middleware.SessionMiddleware',
45+
'django.middleware.common.CommonMiddleware',
46+
'django.middleware.csrf.CsrfViewMiddleware',
47+
'django.contrib.auth.middleware.AuthenticationMiddleware',
48+
'django.contrib.messages.middleware.MessageMiddleware',
49+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
50+
]
51+
52+
ROOT_URLCONF = 'jan.urls'
53+
54+
TEMPLATES = [
55+
{
56+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57+
'DIRS': [os.path.join(BASE_DIR,'templates')],
58+
'APP_DIRS': True,
59+
'OPTIONS': {
60+
'context_processors': [
61+
'django.template.context_processors.debug',
62+
'django.template.context_processors.request',
63+
'django.contrib.auth.context_processors.auth',
64+
'django.contrib.messages.context_processors.messages',
65+
],
66+
},
67+
},
68+
]
69+
70+
WSGI_APPLICATION = 'jan.wsgi.application'
71+
72+
73+
# Database
74+
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
75+
76+
DATABASES = {
77+
'default': {
78+
'ENGINE': 'django.db.backends.sqlite3',
79+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
80+
}
81+
}
82+
83+
84+
# Password validation
85+
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
86+
87+
AUTH_PASSWORD_VALIDATORS = [
88+
{
89+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
90+
},
91+
{
92+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
93+
},
94+
{
95+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
96+
},
97+
{
98+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
99+
},
100+
]
101+
102+
103+
# Internationalization
104+
# https://docs.djangoproject.com/en/2.1/topics/i18n/
105+
106+
LANGUAGE_CODE = 'en-us'
107+
108+
TIME_ZONE = 'UTC'
109+
110+
USE_I18N = True
111+
112+
USE_L10N = True
113+
114+
USE_TZ = True
115+
116+
117+
# Static files (CSS, JavaScript, Images)
118+
# https://docs.djangoproject.com/en/2.1/howto/static-files/
119+
120+
STATIC_URL = '/static/'

jan/urls.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""jan URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/2.1/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path
18+
from newsapp import views
19+
20+
urlpatterns = [
21+
path('', views.index, name ='index'),
22+
path('admin/', admin.site.urls),
23+
]

jan/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for jan project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jan.settings')
15+
16+
application = get_wsgi_application()

manage.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == '__main__':
6+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jan.settings')
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError as exc:
10+
raise ImportError(
11+
"Couldn't import Django. Are you sure it's installed and "
12+
"available on your PYTHONPATH environment variable? Did you "
13+
"forget to activate a virtual environment?"
14+
) from exc
15+
execute_from_command_line(sys.argv)

newsapp/__init__.py

Whitespace-only changes.
136 Bytes
Binary file not shown.
852 Bytes
Binary file not shown.

newsapp/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

newsapp/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class NewsappConfig(AppConfig):
5+
name = 'newsapp'

newsapp/migrations/__init__.py

Whitespace-only changes.

newsapp/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

newsapp/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

newsapp/views.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# importing api
2+
from django.shortcuts import render
3+
from newsapi.newsapi_client import NewsApiClient
4+
5+
# Create your views here.
6+
def index(request):
7+
8+
newsapi = NewsApiClient(api_key ='950064c202904c90b89cb52b2c859a98')
9+
top = newsapi.get_top_headlines()
10+
sources = newsapi.get_sources()
11+
print('\n\n\n',top)
12+
13+
l = top['articles']
14+
desc =[]
15+
news =[]
16+
url=[]
17+
img =[]
18+
19+
for i in range(len(l)):
20+
f = l[i]
21+
if(f['title']=="" or f['description']=="None"):
22+
continue
23+
news.append(f['title'])
24+
desc.append(f['description'])
25+
url.append(f['url'])
26+
img.append(f['urlToImage'])
27+
mylist = zip(news, desc, img, url)
28+
29+
return render(request, 'newsapp/index.html', context ={"mylist":mylist})
30+

templates/newsapp/index.html

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Wisely</title>
6+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
7+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
9+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
10+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11+
12+
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> -->
13+
<!-- Optional theme -->
14+
</head>
15+
<style type="text/css">
16+
body,html{
17+
background-color: #DAE0E6;
18+
margin:0px;
19+
padding:0px;
20+
}
21+
.navbar{
22+
position: fixed;
23+
top: 0;
24+
width: 100%;
25+
z-index: 2;
26+
border-bottom: 1px solid #DAE0E6;
27+
}
28+
.container{
29+
width: 100%;
30+
left: 0;
31+
32+
}
33+
.options{
34+
margin-top: 55.6px;
35+
width: 100%;
36+
height: 40px;
37+
background-color: white;
38+
}
39+
.card-img-top{
40+
height: 50vh;
41+
}
42+
.card{
43+
margin: auto;
44+
width: 600px;
45+
margin-top: 20px;
46+
}
47+
.card:hover{
48+
/*border: inset 2px solid silver;*/
49+
box-shadow: 1px 1px rgba(0, 0, 255, 0.5);
50+
51+
}
52+
</style>
53+
<body>
54+
<nav class="navbar navbar-expand navbar-light" style="background-color: #fff;">
55+
<!-- Navbar content -->
56+
<a class="navbar-brand">NewsApi</a>
57+
<form class="form-inline">
58+
<input class="form-control mr-sm-2" style="background-color: #F2F2F2;" type="search" placeholder="Search" aria-label="Search">
59+
<button class="btn btn-outline-primary my-2 my-sm-0" type="submit">Search</button>
60+
</form>
61+
</nav>
62+
<div class="options">
63+
s;dks
64+
</div>
65+
66+
<div class="container">
67+
68+
{% for new, des, i, url in mylist %}
69+
<div class="card">
70+
<img src="{{ i }}" class="card-img-top" alt="...">
71+
<div class="card-body">
72+
<h5 class="card-title">{{ new }}</h5>
73+
<p class="card-text">{{ des }}</p>
74+
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p><hr>
75+
<a href="{{ url }}" class="card-link">Read article</a>
76+
</div>
77+
</div>
78+
79+
80+
{% endfor %}
81+
</div>
82+
83+
</body>
84+
</html>

0 commit comments

Comments
 (0)