-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern.py
53 lines (49 loc) · 2.01 KB
/
pattern.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import requests
import sys
from api import API
class Pattern:
def __init__(self, id):
self.id = str(id)
pat_dict = API().search_pattern(id)['pattern']
self.free = pat_dict['free']
self.name = pat_dict['name']
self.downloadable = pat_dict['downloadable']
self.weight = pat_dict['yarn_weight_description']
self.currency = pat_dict['currency']
self.price = pat_dict['price']
self.categories = pat_dict['pattern_categories']
self.attributes = pat_dict['pattern_attributes']
self.type = pat_dict['pattern_type']
self.notes = pat_dict['notes']
self.craft = pat_dict['craft']
self.photos = pat_dict['photos']
if self.photos != []:
self.thumbnail = self.photos[0]['medium_url']
self.sizes = pat_dict['pattern_needle_sizes']
self.url = 'https://www.ravelry.com/patterns/library/' + self.id
#print(self.notes)
def quals(self):
'''returns a dictionary of the qualities we care about for a given pattern of the form
{attributes: list_of_attributes, weight: weight, category: list_of_categories}'''
qual_dict = {}
attribute_list = []
category_list = []
for x in self.attributes:
attribute_list.append(x['permalink'])
qual_dict['attributes'] = attribute_list
qual_dict['weight'] = self.weight
for x in self.categories:
category_list.append(x['name'])
qual_dict['categories'] = category_list
return qual_dict
def likeability_score(self, feels_dict):
quals = self.quals()
hearts_score = 0
for umbrella in ['attributes', 'categories']:
for smol in quals[umbrella]:
if smol in feels_dict[umbrella].keys():
hearts_score += feels_dict[umbrella][smol]
if quals['weight'] in feels_dict['weights']:
hearts_score += feels_dict['weights'][quals['weight']]
return hearts_score