import re
from fpdf import FPDF, HTMLMixin
from django.conf import settings
import os

answers = {
"a1" : "You care to learn more about your own or an individual´s future. Cool and no, we don´t recommend tasseography (though it is always fun if you´re running out of smalltalk at afternoon tea with your great-aunt). You have two choices, depending on how light or heavy you want to dive in. You could start with <b>Swart, Tara (2019): The Source: Open Your Mind, Change Your Life</b> if you´re interested in a mixture of rigorous science and alternative thinking.Ready to go deeper? Let <b>Seligman, M. E., Railton, P., Baumeister, R. F., & Sripada, C. (2016). Homo prospectus </b> help you explore human prospection and basically, humanity. No small feat, right?",
"a2" : "If it´s your company´s future you want to figure out, look no further and perhaps think ahead and plan asking for a raise as well. <b>Peter Schwartz ´ 1991 oeuvre The Art of the Long View: Planning for the Future in an Uncertain World</b> is a classic for a reason and with it´s first hand scenario lessons from Shell Oil in the 80s that you should probably listen to with some good retro tunes, it´s your first step to securing a futurist (business) mindset",
"a3" : "Your primary interest is on your or a country? We recommend starting with <b>Ramírez, Rafael/Angela Wilkinson (2016): Strategic Reframing: The Oxford Scenario Planning Approach.</b> You´ll have trouble finding a foresight practicioner without this book on their shelves or kindle that´s kind of a big deal when it comes to planning and creating a future and ultimately, ensuring a cycle of prospective sensemaking.",
"a4" : "So you want to learn about what´s in store for the world? We like people that go big and since we also care about creating certainty amidst uncertainty and light when things look rather gloomy, go and get yourself a copy of <b>Mason, Paul (2020): Clear Bright Future. A Radical Defence of the Human Being.</b>It's entertaining, it´s definitely not a slow read and it´s also a great starting point if you want to take foresight globally with the help of a radical optimist.",
"a5" : "You want to explore the universe. Fantastic! Start by reading <b>Krznaric, Roman (2020): The Good Ancestor: How to Think Long-Term in a Short-Term World.</b> It might not be your most obvious choice but it´s always good to put things in perspective and this book will give you the necessary grounding to not just go 'Beam me up, Scotty!' anytime you despair over global issues. ",

"b1" : "1-3 years can go by pretty fast but we have you covered and your very hands-on reading recommendation is just a click away (and for free) and very quick reading as well. Edited by Florence herself, <a href='https://www.iss.europa.eu/sites/default/files/EUISSFiles/CP_157.pdf'>Gaub, Florence (ed.) (2020): What if...? 14 futures for 2024. Chaillot Paper No.157</a> offers you 14 ways things can go right or wrong in the very near future. Even if it´s not about the specific area you are interested in, have a look at how in detail this timespan can be explored. ",
"b2" : "So you want to see 3-10 years into the future. Are we allowed to play favorites? Let´s say yes and enjoy the following paper that gives you practical examples from foresight in 2020 for 2030. <a href='https://www.iss.europa.eu/sites/default/files/EUISSFiles/CP_161.pdf'>Gaub, Florence (ed.)(2020): Conflicts to come. 15 scenarios for 2030. Chaillot Paper No.161 is just that as it explores everything from green terror to polar power play between China and Russia.</a>",
"b3" : "Your time horizon is 10 to 50 years? Then we urge you to make a beeline and have a look at <b>Hooper, Rowan (2022): How to Spend a Trillion Dollars: The 10 Global Problems We Can Actually Fix.</b> Not only does pretty much everyone enjoy a good game of what would you do if you won the lottery but this thought experiment is a great lesson on the impact a set amount of money could have applied to different problems.",
"b4" : "The further we look ahead the bigger the level of uncertainty we deal with and 50 to 100 years isn´t your run of the mill prospection. But trust <b>Kaku, Michio (2012): Physics of the Future: How Science Will Shape Human Destiny and Our Daily Lives by the Year 2100</b> to make it easier, doing a lot of the leg work for you by interviewing 300 top scientists and compiling the predicted advances. Almost 500 pages might not look like your typical nightstand read but these tales about what the world might look like are a pretty great choice.",
"b5" : "A hundred year´s from now is always a good place to look, isn´t it? Your chosen timeframe offers plenty of inspiration and if you want to have a good overview of what the main theories are, read <b>Roberts, Adam (2021): It´s the End of the World: But What Are We Really Afraid Of?</b> Here you find everything from Climate Armageddon to religious doomsday scenarios and besides being wonderful conversation material, this book is also a scientific discussion of what we are afraid of. Unless you´re secretly a prepper and hoping for a zombie apocalypse to prove your skills. ",

"c1" : "If your goal for futuring is to reduce risks and minimize threats, you should consider giving this classic a chance: <b>Bernstein, Peter L. (1996): Against the Gods: The Remarkable Story of Risk.</b> Not only offers it a unique historical compilation of how risk has shaped us and why we perceive it the way we do but it also offers backbone to your foresight endeavours ´know thy enemy' style.",
"c2" : "If you strive to understand your options and choices, you are probably thinking among the lines of scenario planning. If you want to do your homework and go beyond the surface,  <b>Chermak, Thomas J. (2017): Foundations of Scenario Planning, The Story of Pierre Wack</b> is your jam. Learn to know the man that shaped much of it to understand the method and let yourself be surprised by where the inspiration behind some great thinking actually came from. ",
"c3" : "If your goal is to seize opportunities, there´s no better way than backcasting. If you don´t know what backcasting is, it´s basically your roadtrip into the future. You know the destination and now just need to figure out where to stop along the route for gas and snacks. You can find <a href='https://web.archive.org/web/20171201034740/https://www.unifg.it/sites/default/files/allegatiparagrafo/07-07-2014/essence-of-backcasting_1996_futures.pdf'>Dreborg, K.H., 'Essence of Backcasting', Futures, Vol.28, No.9, (November 1996), pp. 813-828.</a> online still and it´s the introduction into the method you shouldn´t miss. ",
"c4" : "If your motivation is curiosity or fun, then you´re a future explorer. Explorative futuring will keep you well entertained and we have two reads you want to add to your list to excell: first up the lesser known work, <b>Calum, Chace (ed.)(2019): Stories from 2045: Artificial intelligence and the future of work - a collection of short stories by the Economic Singularity Club.</b> it´s fun, it´s bright, it´s a quick read. Second up, <b>Bregman, Rutger (2014): Utopia for Realists. And How We Can Get There</b> which is a must is you haven´t read it yet.",
"c5" : "If all of the above applies and you want to cover risks, make the best of all opportunities, assuage your curiosity AND understand your options, there´s no better place to start than <b>Tetlock, E. Philip/Dan Gardner (2016): Superforecasting. The Art and Science of Prediction.</b> it´s the first book any budding futurist should read and you won´t ever regret picking it up. Whether you strive to become a superforecaster or not, this book is your how to.",

"d1" : "If  you´re looking forward to what´s ahead you´re an optimist and you´re also very much at an advantage. Nevertheless, since there´s few things more annoying than being constantly told your outlook is too bright, you should prepare yourself and read <b>Sharot, Tali (2011): The Optimism Bias: A Tour of the Irrationally Positive Brain.</b> After this you will not only be able to explain that we all tend to think positive but you´ll be equipped to check your bias where needed. ",
"d2" : "You´re not alone. Most of us feel overwhelmed and we cannot deny that there´s a whole lot of uncertainty ahead. What we also know for a fact is that fear is one of the biggest enemies of good foresight and to this end, <b>Gardner, Daniel (2008): The Science of Fear: Why We Fear the Things We Shouldn't--and Put Ourselves in Greater Danger</b> is your best friend. It´s a refreshing take on risk perception that will empower you to look beyond the scary bits.",
"d3" : "We don´t have to tell you to stay in the now because you´re already doing it (and we´re slightly curious what motivates you to dive into futuring tbh). Knowledge is power and your ultimate booster shot for exploring what lies ahead is <b>Grant, Adam (2021): Think Again: The Power of Knowing What You Don't Know.</b> it´s a bit like a stretching session for your brain as it makes a case for why we all need to stay curious and open our minds to the unexpected.",
"d4" : "If you believe in the possibility of shaping the future then you´re most assuredly a solution-driven thinker and <b>Venkataraman, Bina (2019): The Optimist's Telescope: Thinking Ahead in a Reckless Age</b> is your book.It´s an inspiring and seductive plea for committing to change and draws on real-life political experience in what might seem one of the gloomiest of areas - climate change. When looking to make the world a better place, this is the guide you want.",
"d5" : "You feel like you´re just hanging on. That´s understandabe but also a rather uncomfortable position, especially when around you everyone else seems to be less impacted and you´re wondering if you´re just odd or they´re shortsighted. What might actually help is <b>Clarke, Richard A. (2017): Warnings: Finding Cassandras to Stop Catastrophes.</b> Not only is it slightly satisfying to read about missed warnings, it´s also an enlightening book on why some warnings are heard and others not. After all, good foresight is foresight actually heard.",

"e1" : "If you like to ask a friend for their take, Delphi is your method of choice and you´ll enjoy exploring potential futures with a little help from your friends or favorite experts. Also, you´re in luck because a comprehensive collection of everything you need to fully grasp the pros and cons of this very ancient method arrived recently (in comparison to Ancient oracles) and it´s online and for free: <a href='https://web.njit.edu/~turoff/pubs/delphibook/delphibook.pdf'>Linstone, Harold E./Murray Turrof (ed.)(2002):The Delphi Method. Techniques and Applications</a>",
"e2" : "You´re not shying away from trusting strangers´ opinion and that´s not as irrational as some might be tempted to believe. Read  <b>Surowiecki, James (2005): The Wisdom of Crowds: Why the Many Are Smarter Than the Few and How Collektive Wisdom Shapes Business, Economies, Societies and Nations</b> to learn more about your choice of data collection and why we´re not always smarter alone. Not only are we´re pretty sure you´ll hardy ever pick a bad restaurant or investment going forward, we also know you won´t forget that foresight is a team sport. ",
"e3" : "If you get yourself a guidebook, you´re not only likely to be well prepared in most situations as it does require some foresight but you´re also more likely to trust perceived authority on a topic and that´s not per se a bad thing. What you should read ASAP is the one book that put expertise in politics on the hotseat: <b>Tetlock, Philip E. (2006): Expert Political Judgment: How Good Is It? How Can We Know?</b> After reading this you´ll not only better appreciate good experts but you will also understand what constitutes good judgment and what´s just smoke and mirrors.",
"e4" : "So what does you consulting the weather forecast imply? Well, it shows you have a penchant for e data driven analysis and in that case ´ absolutely up your alley to get better aquainted with open forecasting  platforms such as the one cofounded by one of the big big names in the forecasting world, Philip Tetlock,  <a href='https://www.gjopen.com/'>goodjudgment.</a> Simply put, it´s a bit like betting on horses IF you do your due diligence, just for free and not limited to a track. ",
"e5" : "If you cannot resist your horoscope or a quick glance at what the cards have in store for you, there´s two books you should consider. <b>Ariely, Dan (2010): Predictably Irrational: The Hidden Forces That Shape Our Decisions</b> and <b>Knight, Sam (2022): The Premonitions Bureau. A True Account of Death Foretold</b> both offer you a better understanding of what others deem irrational, the first by a variety of examples and The Premonitions Bureau with a partially eery historic case that will definitely help you make sense of what makes no sense at first glance.",
}

class PDF(FPDF, HTMLMixin):
	def header(self): 
		logo = str(settings.BASE_DIR) + "/static/images/top.png"
		self.image(logo,0, 0, 210)
		self.ln(50)

	def footer(self):
		logo = str(settings.BASE_DIR) + "/static/images/bottom.png"
		self.image(logo,0,250 , 210)


def result(answer):
		answer = re.findall('..', answer)
		message = ""
		for i in answer:
			message = message + str(answers[i]) + " <br><br> "
		return(message)


def create_pdf(message, filename):
	# save FPDF() class into a
	# variable pdf
	pdf = PDF()
	

	# Add a page
	pdf.add_page()
	pdf.set_auto_page_break(True, margin = 2.0)
	pdf.set_right_margin(30.0)
	pdf.set_left_margin(30.0)
	pdf.set_font("Arial", size = 18)
	 
	# create a cell
	pdf.cell(0, 30, txt = "Futuring Starter Kit - Your Profile",
			 ln = 1, align = 'C')
		
	pdf.write_html('<font face="Arial" size="10">' + message + '</face>')
	fpath = str(settings.BASE_DIR) + "/static/pdf/Futurate_YourProfile_" + str(filename) + ".pdf"
	link = "pdf/Futurate_YourProfile_" + str(filename) + ".pdf"


	pdf.output(fpath) 

	

	return(link)

