Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Found the internet!
r/learnpython
r/learnpython
1
Posted by6 months ago

Adventurelib gaming engine with Django

Can one use the adventurelib gaming engine with a Django application? I’d like to create a text based interactive fiction game.

2 comments
100% Upvoted

User avatar
level 1

The one roadblock I foresee arises from the stateless nature of the web. You will either have to (1) save the game state after each request & reload it for the next request, or (2) have each game running in a separate persistent process or container, or (3) some combination of those things.

To judge by the docs, the interactive command line interface is pretty "baked into" Adventurelib, which points to solution 2 — running it as a separate program. It is open source, though, so perhaps you can figure out a way to interface with it directly in your Django app.

2
User avatar
level 2

Thank you!

2
More posts you may like
38
33
26
Subreddit Icon
Posted by5 days ago
26
49 comments
23
Subreddit Icon
Posted by6 hours ago

Hi!

I'm kinda losing my mind. This might be misplaced but it feels like I'm the only one with this problem.

I have to generate a PDF from some sort of template with user data. Our initial solution that made sense was Word form letters. The user, or our staff, can create a word document, get a CSV from a Django Rest Framework serializer, use that as a field source for the form letter, put those in and we fill that in with a python library and generate a pdf with libre office headless.

But now the requirements changed (or were different but product management didn't think that was an issue so it wasn't clearly communicated) and we need to have more logic in there than the form letters allow us to do. Like, "if this field is False just throw out those other fields". Basic Jinja conditionals.

But I literally can't find anything like this. There is ReportLab but they have "contact sales" prices for the version with some sort of template file we could use. And the project is not really warranting "contact sales" prices.

There's of course Latex but I'm the only person in the company that has any experience with Latex and the document should preferably look like a letter from our users so we need to implement some design elements that require a lot of fiddling with Latex and I'd have to do it but paying for an engineer to do the job of an intern is not a good idea.

All I find is basically printing HTML generated from a Jinja template but I just don't find anything that supports headers and footers. We need stuff like page numbers and disclaimers in the footer, company logo in the header and it looks like Latex is the only option.

Even Pandoc seems to require you to put some Latex in the metadata it will use to generate a header.

Am I just missing an obvious solution or is this really a very unsolved problem?

23
14 comments
22
Subreddit Icon
Posted by14 hours ago

Hello, This is more of a career question. I am hoping you guys don’t mind it and offer some advice.

I am a biology guy analyzing data and do some programming. I started my new job recently (health care company - we make django apps for exclusive inside collaborators) and am on the training - teaching myself django. The other day, my manager asked me to take over my senior’s programs and django apps because the senior guy (also a biology guy) is going to take personal leave for three months soon. He’s been working for the company for 5 years so he’s made many django apps and programs.

When I looked at the django apps, it seems like all the source code is very complicated and messy (each view.py has about 1000~1800 lines)- lack of documentations, too many local variables named f, rep, ch…like that and pretty much no comment. It is tricky for me to follow what the functions do. I am also a bad python programmer, so I can easily notice bad and spaghetti code. Oh we use python2… 😭

The bottom line is I don’t really think I can take over his django apps and programs and address them when he is on personal leave. But my manager assigned me to handle them. How can I convince him that I am not capable of maintaining his apps and programs? I have been very worried about it so I talked to him about my concerns but he didn’t seem convinced. He said I can do it. I am not sure what to do except for asking as many questions as possible before he leaves. Any thoughts or advice?

p.s. I work in the US. Sorry about my English.

22
17 comments
19
Subreddit Icon
Posted by3 days ago
19
40 comments
19
Subreddit Icon
Posted by6 days ago
19
39 comments
14
Subreddit Icon
Posted by2 days ago

Youtube Link: https://youtu.be/t-luXFgD5Gk

Web Scraping with Python

Objective: To scrape a List of American films of 2022

from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup

URL  = "https://en.wikipedia.org/wiki/List_of_American_films_of_2022"


def crawl(url):
  try:
      html = urlopen(URL)
      soup = BeautifulSoup(html.read(), 'html.parser')
      return soup
  except HTTPError as e:
    print(e)
  except URLError as e:
    print('The server could not be found!')
  else:
    print('It Worked!')

soup = crawl(URL)
tables = soup.find_all('table',{"class":"wikitable"})
# Extracting Highest-grossing films of 2022
hg_table = tables[0]
rows = hg_table.find_all('tr')
header = [h.text.strip() for h in rows[0].find_all('th')] 
highest_grosser_datas=[]

for r in rows[1:]:
  data = {}
  rank = r.find('th').text.strip()
  data[header[0]] = rank
  for i,c in enumerate(r.find_all("td")):
    data[header[i+1]] = c.text.strip()
  print(data)
  highest_grosser_datas.append(data)
------------------------------------------------------------------------------
{'Rank': '1', 'Title': 'Top Gun: Maverick*', 'Distributor': 'Paramount', 'Domestic Gross': '$716,351,712'}
{'Rank': '2', 'Title': 'Doctor Strange in the Multiverse of Madness', 'Distributor': 'Disney', 'Domestic Gross': '$411,331,607'}
{'Rank': '3', 'Title': 'Jurassic World Dominion', 'Distributor': 'Universal', 'Domestic Gross': '$376,009,080'}
{'Rank': '4', 'Title': 'The Batman', 'Distributor': 'Warner Bros.', 'Domestic Gross': '$369,345,583'}
14
2 comments
See more posts like this in r/learnpython