Last active
October 30, 2019 13:15
-
-
Save serverhorror/e173bca7ae310fd70aa361bcd9a3a7a6 to your computer and use it in GitHub Desktop.
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
from __future__ import print_function | |
import os | |
import sys | |
class model(): | |
""" This is the django base model class, just for this example! | |
""" | |
pass | |
class PlayerModel(model): | |
"""This is the part that you write in Django | |
""" | |
profileLink = None # model.String..... | |
marketValueTrend = None # model.String..... | |
currentPrice = None # model.Decimal | |
def post_init(self, profileLink, marketValueTrend, currentPrice): | |
self.profileLink = profileLink | |
self.marketValueTrend = marketValueTrend | |
self.currentPrice = currentPrice | |
def save(self): | |
""" This is not written by you! | |
""" | |
pass ## will never fail (for our required guarantees) | |
class Player(): | |
"""This is where the logic happens | |
* go to the internet | |
* have a beer | |
.... | |
* fail?? (optional) | |
""" | |
profileLink = None | |
attributes = None | |
def __init__(self, profileLink): | |
self.profileLink = profileLink | |
self.attributes = {} | |
# # in Django this takes care about the | |
# # "Django" stuff (defined in the django.model thingie) | |
# super(PlayerLink, model) | |
def updateAttributes(self): | |
## this could also be more code that uses requests.get ... | |
if not self.attributes.has_key('marketValueTrend'): | |
self.attributes['marketValueTrend'] = self.profileLink.replace("profil", "marktwertverlauf") | |
def getMarketValueTrend(self): | |
if not playerMarketValueTrend: | |
self.playerMarketValueTrend = profileLink.replace("profil", "marktwertverlauf") | |
def getDataObject(self): | |
pm = PlayerModel() | |
pm.post_init(self.profileLink, self.attributes['marketValueTrend'], 123.5) | |
return pm | |
if __name__ == "__main__": | |
pass | |
p1 = Player(profileLink="http://example.com/profile/123455") | |
print(p1) | |
print(p1.attributes) | |
p1.updateAttributes() | |
print(p1) | |
print(p1.attributes) | |
pm = p1.getDataObject() | |
print(pm) | |
print(pm.profileLink) | |
print(pm.marketValueTrend) | |
print(pm.currentPrice) | |
pm.save() | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment