Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions BeautifulSoup/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@

soup = BeautifulSoup(source, 'lxml')

csv_file = open('cms_scrape.csv', 'w')
with open('cms_scrape.csv', 'w') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['headline', 'summary', 'video_link'])

csv_writer = csv.writer(csv_file)
csv_writer.writerow(['headline', 'summary', 'video_link'])
for article in soup.find_all('article'):
headline = article.h2.a.text
print(headline)

for article in soup.find_all('article'):
headline = article.h2.a.text
print(headline)
summary = article.find('div', class_='entry-content').p.text
print(summary)

summary = article.find('div', class_='entry-content').p.text
print(summary)
try:
vid_src = article.find('iframe', class_='youtube-player')['src']

try:
vid_src = article.find('iframe', class_='youtube-player')['src']
vid_id = vid_src.split('/')[4]
vid_id = vid_id.split('?')[0]

vid_id = vid_src.split('/')[4]
vid_id = vid_id.split('?')[0]
yt_link = f'https://youtube.com/watch?v={vid_id}'
except Exception as e:
yt_link = None

yt_link = f'https://youtube.com/watch?v={vid_id}'
except Exception as e:
yt_link = None
print(yt_link)

print(yt_link)
print()

print()

csv_writer.writerow([headline, summary, yt_link])

csv_file.close()
csv_writer.writerow([headline, summary, yt_link])
Comment on lines -9 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 9-37 refactored with the following changes:

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand All @@ -27,7 +31,7 @@ def profile(request):
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Comment on lines -30 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

return redirect('profile')

else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def form_valid(self, form):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:



class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
Expand All @@ -58,9 +56,7 @@ class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Comment on lines -61 to +59
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostDeleteView.test_func refactored with the following changes:



def about(request):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand All @@ -27,7 +31,7 @@ def profile(request):
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Comment on lines -30 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

return redirect('profile')

else:
Expand Down
8 changes: 2 additions & 6 deletions Django_Blog/11-Pagination/django_project/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def form_valid(self, form):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:



class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
Expand All @@ -71,9 +69,7 @@ class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Comment on lines -74 to +72
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostDeleteView.test_func refactored with the following changes:



def about(request):
Expand Down
8 changes: 6 additions & 2 deletions Django_Blog/11-Pagination/django_project/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand All @@ -27,7 +31,7 @@ def profile(request):
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Comment on lines -30 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

return redirect('profile')

else:
Expand Down
8 changes: 2 additions & 6 deletions Django_Blog/12-Password-Reset/django_project/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def form_valid(self, form):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:



class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
Expand All @@ -71,9 +69,7 @@ class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Comment on lines -74 to +72
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostDeleteView.test_func refactored with the following changes:



def about(request):
Expand Down
8 changes: 6 additions & 2 deletions Django_Blog/12-Password-Reset/django_project/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand All @@ -27,7 +31,7 @@ def profile(request):
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Comment on lines -30 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

return redirect('profile')

else:
Expand Down
8 changes: 2 additions & 6 deletions Django_Blog/13-AWS-S3-Uploads/django_project/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def form_valid(self, form):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:



class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
Expand All @@ -71,9 +69,7 @@ class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Comment on lines -74 to +72
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostDeleteView.test_func refactored with the following changes:



def about(request):
Expand Down
8 changes: 6 additions & 2 deletions Django_Blog/13-AWS-S3-Uploads/django_project/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand All @@ -27,7 +31,7 @@ def profile(request):
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Comment on lines -30 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

return redirect('profile')

else:
Expand Down
8 changes: 2 additions & 6 deletions Django_Blog/13-Deployment-Heroku/django_project/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def form_valid(self, form):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:



class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
Expand All @@ -71,9 +69,7 @@ class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Comment on lines -74 to +72
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostDeleteView.test_func refactored with the following changes:



def about(request):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand All @@ -27,7 +31,7 @@ def profile(request):
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Comment on lines -30 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

return redirect('profile')

else:
Expand Down
8 changes: 2 additions & 6 deletions Django_Blog/13-Deployment-Linode/django_project/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def form_valid(self, form):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:



class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
Expand All @@ -71,9 +69,7 @@ class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):

def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Comment on lines -74 to +72
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostDeleteView.test_func refactored with the following changes:



def about(request):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def register(request):
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Comment on lines -13 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

return redirect('login')
else:
form = UserRegisterForm()
Expand All @@ -27,7 +31,7 @@ def profile(request):
if u_form.is_valid() and p_form.is_valid():
u_form.save()
p_form.save()
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Comment on lines -30 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

return redirect('profile')

else:
Expand Down
8 changes: 4 additions & 4 deletions Ex-Machina/ex-machina.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def prime(n,x):
i = 1
j = 1
while j <= n:
if x[i] == 1:
j = j + 1
i = i + 1
if x[i] == 1:
j += 1
i += 1
Comment on lines -17 to +19
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function prime refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

return i - 1
x=sieve(10000)
code = [1206,301,384,5]
key =[1,1,2,2,]

sys.stdout.write("".join(chr(i) for i in [73,83,66,78,32,61,32]))
for i in range (0,4):
for i in range(4):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 26-26 refactored with the following changes:

sys.stdout.write(str(prime(code[i],x)-key[i]))

print
Loading