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
File renamed without changes.
15 changes: 10 additions & 5 deletions Awesome-Scripts/get_xkcd_comic.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#!/usr/bin/python
"""Scrapes xkcd comics and saves their images."""

import io
import sys
import requests
from bs4 import BeautifulSoup
import io
from PIL import Image


def crawler(max_pages):
"""Main function for this script; crawls xkcd.com and fetches the images."""

page = 1
next_url = ''
while page <= max_pages:
url = 'https://xkcd.com' + next_url
soup = BeautifulSoup(requests.get(url).text, "lxml")
next_url = soup.findAll('a', {'rel': 'prev', 'accesskey': 'p'})[0].get('href')
next_url = soup.findAll(
'a',
{'rel': 'prev', 'accesskey': 'p'}
)[0].get('href')
image_source = str(soup.findChild('div', {'id': 'comic'}))
soup2 = BeautifulSoup(image_source, "lxml")
image_url = 'https:' + soup2.findAll('img')[0].get('src')
im = requests.get(image_url)
image = Image.open(io.BytesIO(im.content))
img = requests.get(image_url)
image = Image.open(io.BytesIO(img.content))
image.save(sys.argv[2]+image_url.split('/')[4])
page += 1

Expand Down
34 changes: 17 additions & 17 deletions Awesome-Scripts/hackernews.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#!/usr/bin/env python
"""Script to scrape Hackernews and retrieve top 10 links."""

from __future__ import print_function
import requests
from bs4 import BeautifulSoup

# get the front page from hacker news
# Get the front page from hacker news.
response = requests.request("GET", "https://news.ycombinator.com/")

# convert the response to soup
# Convert the response to soup.
soup = BeautifulSoup(response.text, "lxml")

# count the things that get processed
# Count the things that get processed.
count = 0

# process all of the things! :D
for things in soup("tr", { "class" : "athing" }):
# get at the rank of each thing
for rank in things("span", { "class" : "rank" }):
print( rank.text, end=' ' )
# Process all of the things! :D
for things in soup("tr", {"class": "athing"}):
# Get at the rank of each thing.
for rank in things("span", {"class": "rank"}):
print(rank.text, end=' ')

# get the title of each thing
for title in things("a", { "class" : "storylink" }):
print( title.text )
print( title['href'] )
print( " " )
# Get the title of each thing.
for title in things("a", {"class": "storylink"}):
print(title.text)
print(title['href'])
print()

count = count + 1
count += 1

if count == 10: break
if count == 10:
break
118 changes: 118 additions & 0 deletions Awesome-Scripts/myMail_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env python3
# Requires a secret.pyc file containing email credentials for running
"""
Manage your gmail right from your terminal!
Ensure that you have a secret.pyc file for your credentials, with format:
###
MAILBOX = "your_gmail_username"
PASSWD = "your gmail password"
###
You might need to enable access to less secure apps in your gmail settings.
"""

from imaplib import IMAP4_SSL
from smtplib import SMTP_SSL, SMTPAuthenticationError
from poplib import POP3_SSL, error_proto
import pydoc

try:
from secret import * # Gets credentials for gmail account.
except ImportError:
print("Please create a secret.pyc file for your credentials.")
exit()

from socket import gaierror
import subprocess
from time import sleep

SMTPSVR = 'smtp.gmail.com'
IMAPSVR = 'imap.gmail.com'
who = MAILBOX + '@gmail.com'
def send_msg():
with open('email', 'w') as msg:
msg.write('From: YOUR_NAME_HERE <%s>\n' % who)
msg.write('To: RECIPIENTS_HERE\n')
msg.write('Subject: YOUR_SUBJECT_HERE\n\n')
subprocess.call(['nano', 'email'])

with open('email', 'rb') as msg:
body = msg.read().decode('unicode_escape') # INCLUDES HEADERS

body_list = body.split('\n')
breaker = body_list.index('')
origHeaders = body_list[:breaker] # List
recipients = origHeaders[1].split(', ')
origBody = '\n'.join(body_list[breaker+1:])
try:
sendSvr = SMTP_SSL(SMTPSVR, 465)
except gaierror:
print("Can't connect to %s." % SMTPSVR)
exit()
sendSvr.ehlo()
#sendSvr.starttls()
try:
sendSvr.login(who, PASSWD)
except SMTPAuthenticationError:
print("Invalid SMTP credentials.")
exit()
errs = sendSvr.sendmail(who, recipients, body)
sendSvr.quit()
assert len(errs) == 0, errs
print("Email sent!")

wanna_mail = input("Welcome to your email client. Would you like to compose an email? (Y/N) ")
if wanna_mail == 'Y':
send_msg()
else:
print("Alright. Now your inbox will be displayed.")
# IMAP stuff below.
try:
recvSvr = IMAP4_SSL(IMAPSVR, 993)
except gaierror:
print("Can't connect to %s." % IMAPSVR)
exit()
try:
recvSvr.login(who, PASSWD)
except Exception:
print("Can't login. Check your credentials and try again.")
exit()
rsp, msgs = recvSvr.select('INBOX', True)
length = input("How many latest email would you like to be displayed? ")
low = int(msgs[0]) - int(length)
if low <= 0:
low = 1
#try:
rsp, data = recvSvr.fetch("%s:%s" % (low, int(msgs[0])), '(BODY[HEADER])')
#except Exception:
# print("Can't fetch email.")
# exit()
titles = []
for item in data:
if isinstance(item, tuple):
mid = item[0].decode('unicode_escape').split()[0]
for line in item[1].decode('unicode_escape').split('\r\n'):
if line.startswith('Subject:'):
sub = line
break
titles.append(mid + ' - ' + sub)

string = '\n'.join(titles[::-1])
string = 'Use message id to access a specific email.\n\n' + string
print(string)
while 1:
mid = input("Enter the mid of the message you want to read, or skip to quit: ")
if not mid:
break

rsp, data = recvSvr.fetch(mid, '(RFC822)')
stuff = data[0][1].decode('unicode_escape').split('\r\n')
for i in range(len(stuff)):
if stuff[i].startswith('From:'):
break
headers = stuff[i:i+3]
breaker = stuff.index('')
body = stuff[breaker:] #includes the empty string
msg_to_be_displayed = '\n'.join(headers + body)
pydoc.pager(msg_to_be_displayed)

print("Thanks for using the client. Exit done.")