Skip to content

Commit

Permalink
Version 1.7
Browse files Browse the repository at this point in the history
- Fix wikipedia
- Fix nasa
- Remove Outdoor Photographer
  • Loading branch information
LucBerge authored Jan 13, 2024
2 parents 207cc01 + bec2543 commit 48cf336
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 128 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: CD
on:
workflow_dispatch:
push:
paths:
- '**/*.py'
branches: [ master ]

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Static analysis
on:
workflow_dispatch:
pull_request:
paths:
- '**/*.py'
branches: [ master, dev ]

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
workflow_dispatch:
push:
paths:
- '**/*.py'
- 'test/**'
- 'wallme/**'
branches: [ dev ]

jobs:
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

[![Version](https://img.shields.io/pypi/v/wallme?label=Version)](https://github.com/LucBerge/wallme/releases)
[![Downloads](https://img.shields.io/github/downloads/lucberge/wallme/total?label=Downloads)](https://github.com/LucBerge/wallme/releases)
[![Test](https://img.shields.io/github/workflow/status/LucBerge/wallme/Test/dev?label=Test)](https://github.com/LucBerge/wallme/actions/workflows/test.yml)
[![Deploy](https://img.shields.io/github/workflow/status/LucBerge/wallme/CD?branch=master&label=Deploy)](https://github.com/LucBerge/wallme/actions/workflows/cd.yml)
[![Test](https://img.shields.io/github/actions/workflow/status/LucBerge/wallme/test.yml?branch=dev&label=Test)](https://github.com/LucBerge/wallme/actions/workflows/test.yml)
[![Deploy](https://img.shields.io/github/actions/workflow/status/LucBerge/wallme/cd.yml?branch=master&label=Deploy)](https://github.com/LucBerge/wallme/actions/workflows/cd.yml)
[![Codecov](https://codecov.io/gh/LucBerge/wallme/branch/dev/graph/badge.svg?token=AH8jbVSPj3)](https://codecov.io/gh/LucBerge/wallme)

<p align="center">
Expand All @@ -18,6 +18,13 @@

Wallme is a python tool to change your wallpaper every day based on websites. You can check WEBSITES.md for a full list ad supported websites (comming soon).

## From GUI
### Install
[Download the latest release on github](https://github.com/LucBerge/wallme/releases).

### Usage
Double click the exe file to open the GUI.

## From CLI
### Install / Update

Expand Down Expand Up @@ -70,13 +77,6 @@ Prank your friends:
wallme -prank
```

## From CLI
### Install
[Download the latest release on github](https://github.com/LucBerge/wallme/releases).

### Usage
Double click the exe file to open the GUI.

## Contribute by adding a new website

1. Fork
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests
bs4
Pillow
pathlib

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setuptools.setup(
name='wallme',
version='1.6',
version='1.7',
author='LucBerge',
author_email='[email protected]',
description="Change your wallpaper every day",
Expand Down
17 changes: 0 additions & 17 deletions test/test_outdoor_photographer.py

This file was deleted.

7 changes: 4 additions & 3 deletions test/test_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ def _test_set_unset_startup(self, full_key):
manager = ManagerFactory().get_manager()

# Get previous value
previous_value = manager.get_startup()
previous_entry_point, previous_value = manager.get_startup()

# Check the value as been set
manager.set_startup(full_key)
value = manager.get_startup()
_, value = manager.get_startup()
assert value == full_key

# Check the value as been unset
manager.unset_startup()
value = manager.get_startup()
_, value = manager.get_startup()
assert value is None

# Restore previous value
if (previous_value is not None):
manager.entry_point = previous_entry_point
manager.set_startup(previous_value)
17 changes: 7 additions & 10 deletions wallme/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self):
0,
960,
540,
self.manager.image)
"")

# LIST LABEL
canvas.create_text(
Expand Down Expand Up @@ -173,7 +173,7 @@ def __init__(self):
self.unset_startup_button["state"] = tk.DISABLED

# Get current startup value
fullkey = self.manager.get_startup()
_, fullkey = self.manager.get_startup()
# If startup value exists
if (fullkey is not None):
# Get key and subkey
Expand All @@ -191,9 +191,9 @@ def __init__(self):
def update_image(self, key):
try:
# Download image
self.manager.download(key)
image_path = self.manager.download(key, True)
# Set image
new_image = Image.open(self.manager.image)
new_image = Image.open(image_path)
new_image = new_image.resize((960, 540))
photo_image = ImageTk.PhotoImage(new_image)
self.image.configure(image=photo_image)
Expand Down Expand Up @@ -222,7 +222,7 @@ def list_items_selected(self, event):
# If key is not None
if (fullkey is not None):
# Get current startup value
current_startup = self.manager.get_startup()
_, current_startup = self.manager.get_startup()
# If selected item is the startup value
if ((current_startup is not None) and ((current_startup in fullkey) or (fullkey in current_startup))):
# Disable set startup button
Expand All @@ -241,11 +241,8 @@ def list_items_selected(self, event):
self.info_button["state"] = tk.NORMAL

# Set image
if (event is None):
self.update_image(fullkey)
else:
thread = threading.Thread(target=self.update_image, args=(fullkey,))
thread.start()
thread = threading.Thread(target=self.update_image, args=(fullkey,))
thread.start()

def entry_has_changed(self, entry):
# Clear listbox selection
Expand Down
56 changes: 27 additions & 29 deletions wallme/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,38 @@ def main():
gui.resizable(False, False)
gui.mainloop()
else:
try:
if (args.list):
for key in WEBSITES.keys():
logger.debug(key + " - " + WEBSITES[key].description)
else:
manager_factory = ManagerFactory()
manager = manager_factory.get_manager()

if (args.unset_startup):
manager.unset_startup()
else:
if (args.info):
manager.info(args.info)
if (args.url):
manager.url(args.url)
if (args.set):
manager.set(args.set)
if (args.set_startup or args.prank):
if (args.prank):
manager.prank()
else:
manager.set_startup(args.set_startup)
if (args.list):
for key in WEBSITES.keys():
logger.debug(key + " - " + WEBSITES[key].description)
else:
manager_factory = ManagerFactory()
manager = manager_factory.get_manager()

except PermissionError:
logger.error("You need admin permission to run this command")
except WallmeException as e:
logger.error(str(e))
except Exception:
traceback.print_exc()
logger.error("Please, report this issue : https://github.com/LucBerge/wallme/issues")
if (args.unset_startup):
manager.unset_startup()
else:
if (args.info):
manager.info(args.info)
if (args.url):
manager.url(args.url)
if (args.set):
manager.set(args.set)
if (args.set_startup or args.prank):
if (args.prank):
manager.prank()
else:
manager.set_startup(args.set_startup)


if __name__ == "__main__":
try:
main()
except PermissionError:
logger.error("You need admin permission to run this command")
except WallmeException as e:
logger.error(str(e))
except Exception:
traceback.print_exc()
logger.error("Please, report this issue : https://github.com/LucBerge/wallme/issues")
except KeyboardInterrupt:
None
28 changes: 17 additions & 11 deletions wallme/managers/linux.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# coding: utf8

import os
from pathlib import Path
from .manager import Manager
from ..exceptions import WallmeException
from .. import utils


class Linux(Manager):

DATA_FOLDER = str(Path.home()) + "/wallme"
USER = os.environ.get('SUDO_USER', os.environ.get('USERNAME'))
DATA_FOLDER = os.path.expanduser(f'~' + USER) + "/wallme"
SERVICE_FILE = "/lib/systemd/system/wallme.service"

def __init__(self, entry_point):
if(not utils.is_admin()):
raise PermissionError()
if('.py' in entry_point):
entry_point = os.popen('sudo runuser -l ' + self.USER + ' -c "which wallme"').read().rstrip()
super().__init__(entry_point, self.DATA_FOLDER)

def set(self, full_key, test=False):
super().download(full_key, test)
image_path = super().download(full_key, False, test=test)
if (not test):
if os.system("/usr/bin/gsettings set org.gnome.desktop.background picture-uri " + self.image) != 0:
if os.system("sudo /usr/bin/gsettings set org.gnome.desktop.background picture-uri " + image_path) != 0:
raise WallmeException("Cannot set wallpaper")

def set_startup(self, full_key):
self.unset_startup()
user = os.popen("who | awk 'FNR == 1 {print $1}'").read().rstrip()
if (not os.path.exists(self.SERVICE_FILE)):
with open(self.SERVICE_FILE, "wt") as f:
f.write("[Unit]\n\
Expand All @@ -31,9 +35,9 @@ def set_startup(self, full_key):
\n\
[Service]\n\
Type=simple\n\
User=" + user + "\n\
Group=" + user + "\n\
ExecStart=/usr/local/bin/wallme -set " + full_key + "\n\
User=" + self.USER + "\n\
Group=" + self.USER + "\n\
ExecStart=" + self.entry_point + " -set " + full_key + "\n\
\n\
[Install]\n\
WantedBy=multi-user.target")
Expand All @@ -48,8 +52,10 @@ def get_startup(self):
# If file not exists
if (not os.path.exists(self.SERVICE_FILE)):
# Return None
return None
return None, None
# Open file
with open(self.SERVICE_FILE, "r") as f:
# Return full key
return f.readlines()[8][37:-1]
# Get line
values = f.readlines()[8].split(' ')
# Return entry point and full key
return " ".join(values[:-2])[10:], values[-1][:-1]
2 changes: 1 addition & 1 deletion wallme/managers/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, entry_point):
super().__init__(entry_point, self.DATA_FOLDER)

def set(self, website, subkey, test=False):
super().download(website, subkey, test)
super().download(website, subkey, False, test=test)
# if(not test):
# print("=====" + subprocess.Popen(self.SET_SCRIPT % self.IMAGE, shell=True) + "=======")
# if subprocess.Popen(self.SET_SCRIPT%self.IMAGE, shell=True) != 0:
Expand Down
24 changes: 18 additions & 6 deletions wallme/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@

class Manager():

IMAGE_NAME = "wallme.jpg"
BACKGROUND_IMAGE_NAME = "background.jpg"
GUI_IMAGE_NAME = "gui.jpg"
PRANK_KEY = "reddit.sexywomanoftheday"

def __init__(self, entry_point, data_folder):
if('.py' in entry_point):
entry_point = 'wallme'
self.entry_point = entry_point
if (not os.path.isdir(data_folder)):
os.makedirs(data_folder, 493)
self.image = os.path.join(data_folder, self.IMAGE_NAME)
self.background_image = os.path.join(data_folder, self.BACKGROUND_IMAGE_NAME)
self.gui_image = os.path.join(data_folder, self.GUI_IMAGE_NAME)
self.today = datetime.date.today()

def download(self, full_key, test=False):
def download(self, full_key, gui, test=False):
# Parse full key
website, subkey = utils.get_website_subkey_from_fullkey(full_key)
# Pre process
Expand All @@ -30,11 +34,19 @@ def download(self, full_key, test=False):
# Download image
logger.debug("Downloading image from " + image_url, flush=True)
img_data = requests.get(image_url, headers=website.HEADERS).content
with open(self.image, 'wb') as handler:
# Choose the image path
if(gui):
image_path = self.gui_image
else:
image_path = self.background_image
# Save the image file
with open(image_path, 'wb') as handler:
handler.write(img_data)
logger.debug("Image saved to " + self.image)
logger.debug("Image saved to " + image_path)
# Post process
website.post_process(self.image)
website.post_process(image_path)
#Return the image path
return image_path

def info(self, full_key, test=False):
# Parse full key
Expand Down
Loading

0 comments on commit 48cf336

Please sign in to comment.