Giter VIP home page Giter VIP logo

stregsystemet-cli's Introduction

Stregsystemet-CLI

This repository is the Stregsystemet CLI, to buy things in Stregsystemet, at AAU. Use of this cli-tool is at your own risk and there will be no support guarranteed. Either try to resolve the issue yourself and submit a PR or write an issue.

Requirements

The CLI is a python script that relies on no external dependendencies except requests and urllib3. The script is tested with python 3.9

Installation

To install the script, simply cURL or wget it from GitHub

### For quick setup ON LINUX
wget -O "$HOME/.local/bin/sts" https://raw.githubusercontent.com/f-klubben/stregsystemet-cli/master/main.py # To download the script
chmod u+rwx "$HOME/.local/bin/sts" # For permission
sts -s # For setup

### For general purpose
wget -O sts https://raw.githubusercontent.com/f-klubben/stregsystemet-cli/master/main.py

Using the CLI in Powershell can be made easier by running the setup script, you can wget it.

wget https://raw.githubusercontent.com/f-klubben/stregsystemet-cli/master/setup.ps1

Installing it as a package in nix.

environment.systemPackages = [
	(import (fetchTarball "https://github.com/f-klubben/stregsystemet-cli/archive/master.tar.gz") {})
]

Usage

$ sts -h
usage: sts [-h] [-u [USER]] [-i [ITEM]] [-c [COUNT]] [-b] [-l] [-p MONEY] [-a] [-o] [-s] [product]

positional arguments:
  product               Specifies the product to buy

optional arguments:
  -h, --help            show this help message and exit
  -u [USER], --user [USER]
                        Specifies your Stregsystem username
  -i [ITEM], --item [ITEM]
                        Specifies the item you wish to buy
  -c [COUNT], --count [COUNT]
                        Specifies the amount of items you wish to buy
  -b, --balance         Output only stregdollar balance
  -l, --history         Shows your recent purchases
  -p MONEY, --mobilepay MONEY
                        Provides a QR code to insert money into your account
  -a, --update          Update the script and then exists
  -o, --shorthands      Shows shorthands
  -s, --setup           Creates a .sts at /home/<user> storing your account username

If either the user or item arguments or no arguments at all are specified the CLI will enter interactive mode.

The script also keeps track of your balance and what items are available in Stregsystemet.

Contributions

Contributions are welcome!

Feel free to fork the project and create a pull request. To get started with a development environment of Stregsystemet, go to the official Stregsystemet repository

stregsystemet-cli's People

Contributors

falkecarlsen avatar jbjjbjjbj avatar joandrsn avatar mkklausen avatar rawrior avatar sebbadk avatar zaph-x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stregsystemet-cli's Issues

Insufficient funds should print a warning

If I try to purchase a product I cannot afford, I currently get the following message:

$ sts classic
Du har ikke købt din vare. Prøv igen 402

I would suggest printing a better message. Possibly with a QR code to pay.

Plugin Download Functionality

Because STS knows of the location for plugins (If this has been set) STS knows where to put downloaded plugins by itself.
This allows for expansion on the notion that STS is its own package manager, because we can pull plugins directly from github.

Floating point issue

image
Floating points are a pain. They are never accurate. We must round these off for sts to seem pure and complete

Setup flag

Currently, not many people know about the .sts files. It would be beneficial for the user to be able to generate it automatically, with correct formatting.

As a user
I want to have a setup flag that generates a .sts file
So it is placed in the right directory

Perform user validation for qr code creation

When a user wants to insert F$ onto their account, but do not have a .sts file, they are prompted to enter their username.
Currently we do not validate this username meaning you can insert money into a non-existing account.

As a user
I want to ensure the money are sent to an existing account
So that the TREO will not be bothered

Check if __file__ is read-only

@SEbbaDK from #33

Opdateringsfunktionaliteten fra #32 virker ikke i nixos pr. design, siden programmet bliver lagt i read-only hukommelse.
Så det kunne være en idé at checke for om file kan skrives til.

Print shorthands for the user

#13 added shorthand which was great.
Unfortunately, I find myself: is there a shorthand for this id?

I would suggest adding an option to print all of the shorthands to the user so they can make an informed decision on what product to purchase.

Feature to list previous purchases

I wish to add a feature, where you can list your previous purchases.
Stegsystemet already has this data, by visiting /<roomID>/user/<userID>/ and it would be possible to get the userID from the test user function
From here we simply need to scrape the loaded website and parse the table, containing product, date, and price.

Remove HTML tags from products

It would be nice if the HTML tags used to highlight products would removed from the CLI as it just looks bad (Such as <h1>). Alternatively the products with html tags could also be used to change the formatting of products with these tags.

NameError on Windows system after entering username

Running the Stregsystem CLI on Windows results in the following error:
NameError: name 'is_windows_terminal' is not defined

This can be fixed if the reference to is_windows_terminal is replaced with is_windows. I imagine that short-circuiting prevents the error from being found from a Linux system.

Add qr code functionality

As a fember I want a QR code to insert money in my terminal, so I don't have to remember the phone number and my username.

CTRL+D should not throw EOFError

ctrl+d in most shells issue an EOF character, which is a relatively universal way of ending a shell or other text input (like the buy menu in sts).
We should just gracefully handle this character and exit.

Id> Traceback (most recent call last):
File "/bin/sts", line 416, in <module>
    main()
File "/bin/sts", line 400, in main
    user_buy(args.user)
File "/bin/sts", line 294, in user_buy
    item, count = get_item([x[0] for x in wares])
File "/bin/sts", line 260, in get_item
    item_id = input('Id> ')
    
EOFError

Unable to run SETUP flag on clean install

When creating a new installation of STS, running the -s flag produces the following stacktrace:

Traceback (most recent call last):
  File "/opt/homebrew/bin/sts", line 1032, in <module>
    sts.load()
  File "/opt/homebrew/bin/sts", line 643, in load
    self._argument_handler.handle_stopping(self, self._user_manager, self._request_handler)
  File "/opt/homebrew/bin/sts", line 296, in handle_stopping
    self.setup_sts(user_manager, request_handler, Configuration())
  File "/opt/homebrew/bin/sts", line 395, in setup_sts
    configuration.write()
  File "/opt/homebrew/bin/sts", line 162, in write
    with open(paths[0], 'w') as configfile:
IndexError: list index out of range

This has been tested on MacOS

Add a --dry-run option to the tool

For new users who are unfamiliar with the code, they might want to explore what the tool can do.

I would suggest adding a --dry-run option for the script.
Example usage:

$ sts classic --dry-run
Username 'abba' would purchase 1x 14 Øl(Grøn/Classic/Rød/Rå) (excl. pant) for 6.67 kr

Another example:

$ sts -u johannes 1837 --dry-run
Username 'johannes' would purchase 1x 1837 Monster / cola energy (excl. pant) for 12.10 kr

More reading on general usage of --dry-run here

Plugin help message suggestion does not work

STS writes the following when 'plugin_dir' is not set:
STS now supports plugins. Add "plugin_dir=~/.sts_plugins/" to your .sts file

However, (on my system at least) the expansion of home (~) does not work and I have to give it a FQN (/home/$user/.config/sts/plugins/etc).

Having some way to supress the "heyo, we got plugins" message without having to setup plugins would be nice, since you can know of the support but choose not to use it.

Enable multibuy in username prompt

Fembers have been crashing the sts CRT terminal by trying to use multibuy in the username prompt. While this does make a sale, and should do so, we need to implement support for this, such that the system will not crash when a request like that is made

Error running sts following the setup -s process

Running the setup -s process creates a .sts file containing two [sts], resulting in an error the next time you run "sts".

Terminal:

sts -s
Hvad er dit bruger navn? <Username>

~/.sts

[sts]
[sts]
<username>

To fix the problem i removed one instance of [sts] in the .sts file.

~/.sts

- [sts]
  [sts]
  <username>

Requests module is a dependency

sts must be dependency free. Therefore the requests module must be replaced with raw urllib3 calls. Pure python is a requirement

Separate functionality - Creation of stslib.py

Currently I'm trying to create a rofi script for STS. In this regard, I would like to use the get-wares-functionality.
However this function is tightly bound to the main python file.
I suggest splitting the functionality into the following files:

  • stslib.py - A general library containing interaction with stregsystemet. So: test_user, get_wares, get_history, sale and possibly get_qr
  • sts.py - The current implemention, but calling the library instead
  • sts-strandvejen.py - The special case of the strandvejen

And here is where I would be able to create sts-rofi.py which interacts with rofi.

This split does however come with a drawback: The update script needs to support updating multiple files.

Currently it is only a suggestion. I don't know if there is even any support a change like this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.