This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pylast | |
import secretstorage | |
import requests | |
from pycookiecheat import chrome_cookies | |
########## | |
# CONFIG # | |
########## | |
# You have to have your own unique two values for API_KEY and API_SECRET | |
# Obtain yours from https://www.last.fm/api/account/create for Last.fm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib as hasher | |
class Block: | |
def __init__(self, index, timestamp, data, previous_hash): | |
self.index = index | |
self.timestamp = timestamp | |
self.data = data | |
self.previous_hash = previous_hash | |
self.hash = self.hash_block() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
# Everyone in queue, and their desired order | |
customers = [('Bob', 'Ham Sandwich'), ('Paul', 'Grilled Cheese'), ('Sally', 'Chicken Croissant')] | |
# make a sandwich, but pause(yield) to deliver it | |
def make_sandwiches(): | |
for customer in customers: | |
time.sleep(1) # making the sandwich for our customer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def employees(): | |
for y in ['Bob', 'Sally', 'Jake']: | |
yield y | |
def customers(): | |
for ex in ['James', 'Ted', 'Kent']: | |
yield ex | |
def retrieve_all_users(): | |
yield from employees() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def employees(): | |
for y in ['Bob', 'Sally', 'Jake']: | |
yield y | |
def customers(): | |
for ex in ['James', 'Ted', 'Kent']: | |
yield ex | |
def retrieve_all_users(): | |
for employee in employees(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_sandwich(): | |
customer = yield 'No Customer' | |
print(customer) | |
action = make_sandwich() | |
print(next(action)) | |
print(action.send(13)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def make_sandwich(customers): | |
for customer in customers: | |
time.sleep(1) # let's pretend this is the time it takes to make the sandwich | |
yield customer | |
maker = make_sandwich(['Bob', 'Paul', 'Sally']) | |
print('Just made a sandwich for:', next(maker)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
# As people enter the queue, take their order, but pause(yield) to make their sandwich | |
def get_next_customer(): | |
# people are going to be adding themselves to this queue and it will grow quickly | |
list_of_customers = [('Bob', 'Ham Sandwich'), ('Paul', 'Grilled Cheese'), ('Sally', 'Chicken Croissant')] | |
for an_order in list_of_customers: | |
yield an_order | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
# Everyone in queue, and their desired order | |
def get_customers(): | |
return [('Bob', 'Ham Sandwich'), ('Paul', 'Grilled Cheese'), ('Sally', 'Chicken Croissant')] | |
customers = get_customers() | |
# make the sandwiches for all the customers, then deliver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
headers = { | |
"Rest-Impersonate-User": userid, | |
"Rest-User-Token": "XXXXXXXXXXXXXXXXXXXXXXX", | |
} | |
try: | |
json = { | |
'ThreadId': thread_id, | |
'ForumId': 21, | |
'Body': data['raw'], | |
'PostDate': data['created_at'].strftime("%Y-%m-%d %H:%M:%S") |