How to use latest_screenshot method in Selene

Best Python code snippet using selene_python

blog.py

Source:blog.py Github

copy

Full Screen

...85 fp.write("# Untitled\n\n")86 fp.write("[original file name %s](%s)\n\n" % (os.path.split(fpath)[1], fpath))87 # edit post88 os.system('open -a typora %s' % fpath_post)89def latest_screenshot():90 fpaths = glob.glob(os.environ['HOME'] + "/Desktop/Screen Shot *.png")91 fpaths = sorted(fpaths, key=get_mtime, reverse=True)92 return fpaths[0]93if __name__ == '__main__':94 if len(sys.argv) == 1:95 os.chdir(BLOG_LOC)96 os.system('open -a typora .')97 elif sys.argv[1] == 'ls':98 os.system('ls -l '+BLOG_LOC)99 elif sys.argv[1] in ['new', 'md']:100 os.chdir(BLOG_LOC)101 fpath = gen_fname_post('.md')102 print('creating: %s' % fpath)103 os.system('touch %s' % fpath)104 os.system('open -a typora %s' % fpath)105 elif sys.argv[1] in ['newtxt', 'txt']:106 os.chdir(BLOG_LOC)107 fpath = gen_fname_post('.txt')108 print('creating: %s' % fpath)109 os.system('touch %s' % fpath)110 os.system('open -a macvim %s' % fpath)111 elif sys.argv[1] == 'compile':112 entries = os.listdir(BLOG_LOC)113 entries = filter(lambda x: re.match(r'\d\d\d\d.*\.md$', x), entries)114 fp = open(os.path.join(BLOG_LOC, "final.md"), 'w')115 for e in sorted(entries, reverse=True):116 etxt = ''117 path = os.path.join(BLOG_LOC, e)118 print('opening %s' % path)119 with open(path, 'r') as fp2:120 etxt = fp2.read()121 fp.write(etxt + '\n<hr>\n')122 fp.close()123 elif sys.argv[1] in ['show','view']:124 path = os.path.join(BLOG_LOC, 'final.md')125 get_program_output(['open', path])126 elif sys.argv[1] == 'attach':127 attach(sys.argv[2])128 elif sys.argv[1] == 'attachr':129 attach(sys.argv[2], True)130 elif sys.argv[1] in ['attachss','attachscreenshot']:131 attach(latest_screenshot())132 elif sys.argv[1] in ['attachrss','attachscreenshotr']:133 attach(latest_screenshot())134 elif sys.argv[1] == 'screenshot':135 os.chdir(BLOG_LOC)136 init_post_from_image(latest_screenshot())137 elif os.path.isfile(sys.argv[1]):138 fpath = os.path.abspath(sys.argv[1])139 os.chdir(BLOG_LOC)140 fname, fext = os.path.splitext(fpath)141 if fext in ['.jpg', '.jpeg', '.gif', '.png']:142 init_post_from_image(fpath)143 else:144 init_post_from_attach(fpath)145 else:...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1from operator import itemgetter, attrgetter2from django.shortcuts import render3from django.db.models import Max4from screenshotter.models import ElectionUrl, ElectionMirror, ElectionScreenshot5def grouped(xs, key):6 groups = {}7 key = key if callable(key) else itemgetter(key)8 for x in xs:9 k = key(x)10 grp = groups.get(k, [])11 grp.append(x)12 groups[k] = grp13 return groups.values()14def state_index(request):15 state_groups = ElectionUrl.objects.values('state').distinct()16 state_lookup = dict(((grp['state'], grp) for grp in state_groups))17 latest_screenshots = ElectionScreenshot.objects.values('election_url__state').annotate(timestamp=Max('timestamp'))18 for screenshot in latest_screenshots:19 state_lookup[screenshot['election_url__state']]['latest_screenshot'] = screenshot['timestamp']20 latest_mirrors = ElectionMirror.objects.values('election_url__state').annotate(timestamp=Max('timestamp'))21 for mirror in latest_mirrors:22 state_lookup[mirror['election_url__state']]['latest_mirror'] = mirror['timestamp']23 24 states = list(state_lookup.items())25 states.sort(key=itemgetter(0))26 return render(request, "state_index.html", {27 'states': states28 })29def state_details(request, state):30 urls = ElectionUrl.objects.filter(state=state)31 return render(request, "state_details.html", {32 'state': state,33 'urls': urls34 })35def url_details(request, state, sha1, collapsed=False):36 url = ElectionUrl.objects.get(state=state, url_sha1=sha1)37 screenshots = url.screenshots.order_by('timestamp')38 if collapsed:39 screenshot_groups = grouped(screenshots, key=attrgetter('image_sha1'))40 def yield_earliest():41 for grp in screenshot_groups:42 grp.sort(key=attrgetter('timestamp'), reverse=True)43 yield grp[0]44 screenshots = list(yield_earliest())45 mirrors = url.mirrors.order_by('timestamp')46 by_timestamp = {}47 for screenshot in screenshots:48 by_timestamp[screenshot.timestamp] = { 'screenshot': screenshot }49 for mirror in mirrors:50 obj = by_timestamp.get(mirror.timestamp, {})51 obj['mirror'] = mirror52 by_timestamp[mirror.timestamp] = obj53 timeline = by_timestamp.items()54 timeline.sort(key=itemgetter(0))55 return render(request, "url_details.html", {56 'state': state,57 'url': url,58 'screenshots': screenshots,59 'mirrors': mirrors,60 'timeline': timeline,61 'collapsed': collapsed62 })63def data(request):64 states = [grp['state'] for grp in ElectionUrl.objects.values('state').distinct()]65 states.sort()66 return render(request, "data.html", {67 'states': states68 })69def status(request):70 mirrors = ElectionMirror.objects.order_by('-timestamp')71 screenshots = ElectionScreenshot.objects.order_by('-timestamp')72 latest_mirror = None if mirrors.count() == 0 else mirrors[0]73 latest_screenshot = None if screenshots.count() == 0 else screenshots[0]74 return render(request, 'status.html', {75 'latest_mirror': latest_mirror,76 'latest_screenshot': latest_screenshot...

Full Screen

Full Screen

screenshot.py

Source:screenshot.py Github

copy

Full Screen

1import pyautogui2import os3import re4import pygetwindow5# prediction list if user wants to ss the screen6predictions = ['take', 'a', 'screenshot', 'my', 'the', 'screen', 'window', 'app']7# if these indexes are in the search input then user is not trying to ss the screen8abort = ['how', 'search', 'to']9def screenshot():10 images = ''11 # change dir to ss default location, listing the existing screenshots12 os.chdir(f'{os.environ["USERPROFILE"]}\\Pictures\\Screenshots')13 for image in os.listdir():14 images += f'{image} '15 # finding the numbers16 screenshots = re.findall(r'\s*\((\d*)\)', images)17 # converting numbers to int18 latest_screenshot = [int(screenshot) for screenshot in screenshots]19 # getting the highest number, increment by 1, screenshot20 pyautogui.screenshot(f'Screenshot ({max(latest_screenshot) + 1}).png')21def main():22 # getting the hwnd ID of the assistant program23 wolf = pygetwindow.getWindowsWithTitle('Wolf - Assistant')[0]24 # minimize25 wolf.minimize()26 # try screenshot, if folder not found create one27 try:28 screenshot()29 return None, f'Done!'30 except FileNotFoundError:31 os.chdir(f'{os.environ["USERPROFILE"]}\\Pictures\\')32 os.mkdir('Screenshots')33 screenshot()34 return None, f'Done!'35 # microsoft somehow moved the pictures folder to onedrive,36 # it'll return this if above handlers failed.37 except:38 return None, f'{os.environ["USERPROFILE"]}\\Pictures folder not found, please read the documentation to fix it.'39# check input, if counter >= 3 it'll screenshot40def check_userinput(input):41 counter = 042 user_input = input.split()43 for prediction in user_input:44 if prediction in predictions:45 counter += 146 elif prediction in abort: # if any of abort's indexes are in user input then abort47 counter = 048 break49 else:50 pass...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful