pos fix for picons dialog

This commit is contained in:
DYefremov
2018-03-07 23:56:21 +03:00
parent c3e880890e
commit ae6f0e1ae2
2 changed files with 9 additions and 7 deletions

View File

@@ -4,6 +4,8 @@ import shutil
from collections import namedtuple from collections import namedtuple
from html.parser import HTMLParser from html.parser import HTMLParser
import re
from app.commons import log, run_task from app.commons import log, run_task
from app.properties import Profile from app.properties import Profile
@@ -103,6 +105,8 @@ class PiconsParser(HTMLParser):
class ProviderParser(HTMLParser): class ProviderParser(HTMLParser):
""" Parser for satellite html page. (https://www.lyngsat.com/*sat-name*.html) """ """ Parser for satellite html page. (https://www.lyngsat.com/*sat-name*.html) """
_POSITION_PATTERN = re.compile("at\s\d+\..*(?:E|W)']")
def __init__(self, entities=False, separator=' '): def __init__(self, entities=False, separator=' '):
HTMLParser.__init__(self) HTMLParser.__init__(self)
@@ -117,7 +121,6 @@ class ProviderParser(HTMLParser):
self._current_cell = [] self._current_cell = []
self.rows = [] self.rows = []
self._ids = set() self._ids = set()
self._counter = 0
self._positon = None self._positon = None
def handle_starttag(self, tag, attrs): def handle_starttag(self, tag, attrs):
@@ -150,11 +153,10 @@ class ProviderParser(HTMLParser):
elif tag == 'tr': elif tag == 'tr':
row = self._current_row row = self._current_row
# Satellite position # Satellite position
self._counter = self._counter + 1 if not self._positon:
if self._counter == 12: pos = re.findall(self._POSITION_PATTERN, str(row))
pos = str(row) if pos:
pos = pos[pos.rfind("at") + 2:] self._positon = "".join(c for c in str(pos) if c.isdigit() or c in ".EW")
self._positon = "".join(c for c in pos if c.isalnum() or c == ".")
if len(row) == 12: if len(row) == 12:
on_id, sep, tid = str(row[-2]).partition("-") on_id, sep, tid = str(row[-2]).partition("-")

View File

@@ -126,7 +126,7 @@ class PiconsDialog:
providers = self.get_selected_providers() providers = self.get_selected_providers()
for prv in providers: for prv in providers:
if not prv[2].isdigit(): if not prv[2] and prv[2][:-2].isdigit():
self.show_info_message( self.show_info_message(
get_message("Specify the correct position value for the provider!"), Gtk.MessageType.ERROR) get_message("Specify the correct position value for the provider!"), Gtk.MessageType.ERROR)
return return