• Activity
  • Votes
  • Comments
  • New
  • All activity
  • Showing only topics with the tag "python". Back to normal view
    1. Architecture for untrained software engineers (Python)

      Hey everyone, I've been programming for some time now but notice without any formalized education in CS I often get lost in the weeds when it comes to developing larger applications. I'm familiar...

      Hey everyone,

      I've been programming for some time now but notice without any formalized education in CS I often get lost in the weeds when it comes to developing larger applications. I'm familiar with the principles of TDD and SOLID - which have helped with maintainability - however still feel that I'm lacking in the ability to architect a properly structured system. As an example, I'm currently developing a flask REST API for a website (just for learning purposes). This involves parsing a html response and serializing the result as JSON. I'm still quite unclear as to structuring this sort of thing. If any more experienced developers could point me in the right direction/offer up their opinion I'd be very appreciative. Currently I have something like this (based - I hope correctly? - on uncle bob's clean architecture).

      Firstly, I'm defining the domain model. i.e the structure of the API response. Then, from outside in.

      1. Infrastructure (Flask): User makes request via interface (in my case a request to some endpoint)
      2. Adapters: request object checks if the request is valid (on the way back it checks if the response is valid) - Is this layer only for error handling?
      3. Repository: I'm struggling a bit here, AFAIUI this layer is traditionally a database. In my case however, where the request is valid, is this where I should handle the networking layer? i.e all the requests to return the website source? I'm also confused given at this stage I should be returning the relevant domain model, like an ORM, but as my data is unstructured, in order to do this I need to transform the response first. Where would it be best to handle this?
      4. Use Cases: Here I transform the domain model depending on the request. For example, filter all objects by id. Have I understood this correctly?
      5. Serializers: Encode the domain model as JSON to return from flask route.

      If you got this far, thanks so much for reading. I really hope to hear the opinions of more experienced devs who can steer me in the right direction/correct me should I have misunderstood anything.

      8 votes
    2. What is the best way to teach Python for my 11-year-old sister that lives in another state?

      This may seem an obvious question, but not as much as it seems. She uses Windows, I’m currently using Linux/macOS. How to instruct her to install her Python environment? Should I use Zoom, Skype,...

      This may seem an obvious question, but not as much as it seems. She uses Windows, I’m currently using Linux/macOS. How to instruct her to install her Python environment? Should I use Zoom, Skype, Google Hangouts, or another solution? Is there and easy way for live-drawing (online blackboard) to explain things to her visually? And, perhaps most importantly, how can I do that for free?

      13 votes
    3. What's the current state-of-the-art in Python package creation/distribution?

      I've been thinking on and off about packaging up a few simple Python utilities I've written to stick up on Github for people to use if they want, but, every time I go to check out how one goes...

      I've been thinking on and off about packaging up a few simple Python utilities I've written to stick up on Github for people to use if they want, but, every time I go to check out how one goes about managing dependencies and all that for a project, I run into a whole wall of options. Does anyone better versed in all of this have any recommendations for me?

      11 votes
    4. Python challenges or projects with just the standard library?

      I've been slowly learning python for some months already. I used the Python Crash Course book from No Starch Press, it teaches the basics and then goes on with some projects with pygame,...

      I've been slowly learning python for some months already. I used the Python Crash Course book from No Starch Press, it teaches the basics and then goes on with some projects with pygame, matplotlib, etc.

      However, I feel that my Python skills aren't very good yet, and before learning to use libraries I would like to have a better command of the standard library.

      I have been looking for some book with projects or, even better, challenges using just the standard library, but haven't found any good ones. Most of them either are for absolute beginners, or use additional libraries, or are very technical and without focus on practice.

      Do you know of any good book or resource with challenges or projects that don't depend on additional libraries? Or, do you have any idea for a project or challenge using just the standard library?

      Thanks in advance!

      14 votes
    5. Tildee — A python library for interacting with Tildes

      Update! After a few hours of struggling I managed to set up Read the docs for Tildee, it should help using the library significantly. After getting some inspiration from TAPS I thought that maybe...

      Update! After a few hours of struggling I managed to set up Read the docs for Tildee, it should help using the library significantly.

      After getting some inspiration from TAPS I thought that maybe I try to work on something vaguely similar on my own. And after… some? hours of coding today I came up with this: tildee.py (source)
      It's a wrapper for the Tildes Public/Web API that is already used by the site internally to make it work. The obvious problem with that is that it will at one point break when this unstable API is changed. It can do basically all things a normal user can do with the notable exception of applying comment labels (because I haven't gotten around to that yet).

      Example of usage for a DM reply bot (result):

      import sys
      from tildee import TildesClient
      import time
      
      # Initialize client and log in, 2FA isn't supported yet and will probably break in horrible ways
      t = TildesClient("username", "password", base_url="https://localhost:4443", verify_ssl=False)
      
      while True:
          # Retrieve the "unread messages" page and get a list of the conversations there
          unread_message_ids = t.fetch_unread_message_ids()
          for mid in unread_message_ids:
              # Access the conversation history page; this also clears the "unread" flag 
              conversation = t.fetch_conversation(mid)
              # Get the text of the last message
              text = conversation.entries[-1].content_html
              # Abort if it's from the current user (I don't think this could actually happen)
              if conversation.entries[-1].author == t.username:
                  break
              print(f"Found a message by {conversation.entries[-1].author}")
              # If the message contains a reference, reply in kind
              if "hello there" in text.lower():
                  print("Replying…")
                  t.create_message(mid, f"General {conversation.entries[-1].author}! You are a bold one.")
              # Delay before processing next unread message
              time.sleep(3)
          # Delay before next unread check
          time.sleep(60)
      

      This has a lot of potential. Haven't yet figured out potential for what, but I'll take what I can get.
      I'd be really grateful if someone with a little more experience than me (that's not exactly a high bar :P) could give me some pointers on the project's structure and the "API design", hence the ask tag. Other creative ideas for what to use this for are appreciated, too.

      47 votes
    6. I'm tracking state sponsored propaganda online, and I need your help.

      Hey, tildes! A few weeks ago, I brought attention to Russian propaganda being shared on reddit. I deleted my reddit accounts, but I'm still tracking propaganda being shared on social media. The...

      Hey, tildes!

      A few weeks ago, I brought attention to Russian propaganda being shared on reddit. I deleted my reddit accounts, but I'm still tracking propaganda being shared on social media. The midterms are approaching quickly, so I'm asking for your help with the project I'm working on.

      1. Help with code: Improve what exists and add more features, heck, even documentation would be an improvement (I'm not a programmer).

      2. Find more propaganda sites: Right, left, Russian, Jamaican, whatever.

      3. Spread the word: Social media, irl friends, media, politicians, etc.

      78,143 reddit posts total.
      16,831 deceptive Russian reddit posts.
      5,588 deceptive Iranian reddit posts.
      1,416 tweets total.

      Here's the full output. Check the 'Overview' tab first.

      Happy to answer questions if you have any.

      44 votes
    7. Coding Noob Needs Help/Guidance on Small Project

      Hi, There's a certain site which hosts media files and has a player that depends on a lot of third-party resources to play, while browsers have native support for those file types. Those 3rd-party...

      Hi,

      There's a certain site which hosts media files and has a player that depends on a lot of third-party resources to play, while browsers have native support for those file types. Those 3rd-party resources are often blocked by ad blockers and I have no desire to white-list them. I would like to extract the direct link to the media file and make it playable on my custom web page.

      The link to the media file is present in the page source of each page, always on the same line. It's not anchored in HTML but present in the JavaScript for the player, like so:

          $(document).ready(function(){
            $("#jquery_jplayer_1").jPlayer({
              ready: function () {
                $(this).jPlayer("setMedia", {
                  [ext]: "https://[domain]/[filename.ext]"
                });
              },
      

      In this example it's on line #5. [ext] = the file extension.

      I want to build the following:

      • A web page with a form with a single input field meant to receive links from that specific file host
      • [Something] that extracts the file link from the source of the host's page
      • Present the linked file as playable in an embedded native player

      So far I've managed to create a form with an input box and a submit button, but it doesn't do anything yet. What is the best way to build the actual functionality? I know HTML/CSS. I have some rudimentary understanding of JavaScript/jQuery and Python3, so those would be my preferred tools.

      For those worried about piracy: The files in question are not copyrighted and I'm not looking to make copies. I just want to make them playable. This is for personal use.

      Thank you for reading this far. Any and all advice is welcome!

      10 votes
    8. Are Python virtual environments comparable to Docker containers?

      I've been trying to understand Docker and while also learning Python it occurred to me that virtual environments seem to be the same thing. They're probably not, but can anyone shed some light on...

      I've been trying to understand Docker and while also learning Python it occurred to me that virtual environments seem to be the same thing. They're probably not, but can anyone shed some light on this?

      6 votes
    9. News Desk Updated!

      A few weeks ago I posted a project I was working on to read news from the command line. I incorporated the suggestions given in that thread (license, requirements.txt, etc), incorporated...

      A few weeks ago I posted a project I was working on to read news from the command line. I incorporated the suggestions given in that thread (license, requirements.txt, etc), incorporated suggestions I've received elsewhere, and added a few features.

      Here's the updated link: News Desk

      Any feedback would be much appreciated!

      Edit: And a specific point for feedback. I store the user's API key in ~/.nd_config/key which I think is a step up from requiring the user to set their key as an environment variable (which is how I had it originally). Still though, is there some way I can not store the key in plaintext and still have it in a format that is readable by the computer and can be used to verify API access?

      7 votes
    10. Python web developers - what is your favorite framework?

      As some of you may know, Tildes is written in Pyramid. I've done some OSS work in Pyramid and Flask, but my paid web dev work the past few years has been mostly in Django. There are some newer...

      As some of you may know, Tildes is written in Pyramid. I've done some OSS work in Pyramid and Flask, but my paid web dev work the past few years has been mostly in Django. There are some newer frameworks out there like Sanic or Falcon, and some older ones like Zope, CherryPy and Turbogears, that I've played with but have no real experience in.

      Personally, I like Django for its "batteries included" and its big ecosystem, Flask for its minimalism and Pyramid for its elegant design. There's no single framework that fits all needs and all have their share of annoyances - Django can be quite difficult to swap out things like the default ORM or template system (though these have gotten better in recent versions), Flask has some architectural issues with request and other global variables, and Pyramid perhaps suffers from a relatively small ecosystem and lack of "one way to do it".

      What are your experiences and preferences?

      9 votes
    11. I made a thing: News Desk

      I've only been seriously programming for about a year now (and mostly in R), but I've been digging into Python for the past few months. Mostly I use pandas/numpy/scipy/scikit-learn, etc. for data...

      I've only been seriously programming for about a year now (and mostly in R), but I've been digging into Python for the past few months. Mostly I use pandas/numpy/scipy/scikit-learn, etc. for data analysis and some ML stuff, but in an effort to expand my skills I've also been playing around trying to build a few projects.

      It's not much, but I built this: News Desk

      Feedback is welcome. One bug that I'm aware of is that when you refresh the program, the url_list isn't cleared and the URLs from the refreshed articles are just appended to the list. So even though only 20 articles will show, you can select, for example, article 35.

      11 votes