Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a status bar which will be on top of your mac with live ipl score #938

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions shreycriclivemac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
It's a pip installable package so you don't need to download this rep , just go inside your terminal and run the following commands:

```
pip3 install shreycriclivemac==0.4
shreycriclivemac-run
```

After running the above commands, a rectangular bar would appear which will show you the live score of ongoing IPL match or the most recently finished, it auto-refreshes every 30 secs:

<img width="1440" alt="Screenshot 2023-04-15 at 3 56 31 AM" src="https://user-images.githubusercontent.com/89294432/232164982-6df0a892-5fad-4c93-81e0-da0dc576cd05.png">
120 changes: 120 additions & 0 deletions shreycriclivemac/shreycriclivemac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env python

import requests
import lxml.html
from AppKit import *
from bs4 import BeautifulSoup

from AppKit import NSClickGestureRecognizer



class StatusItem(NSObject):
def applicationDidFinishLaunching_(self, notification):
# create a status bar item
statusbar = NSStatusBar.systemStatusBar()
self.statusitem = statusbar.statusItemWithLength_(NSVariableStatusItemLength)

# create a custom view
# create a custom view with a larger rectangle
self.view = NSView.alloc().initWithFrame_(NSMakeRect(0, 0, 200, 20))

self.view.setWantsLayer_(True)
self.view.layer().setBackgroundColor_(NSColor.blackColor().CGColor())



# add the custom view to the status bar item
self.statusitem.setView_(self.view)

# update the score
self.update_score()

# schedule score update every 30 seconds
self.timer = NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(30.0, self, 'update_score', None, True)

# add the custom view to the status bar item
# add the custom view to the status bar item
self.statusitem.setView_(self.view)

# add a click gesture recognizer to the custom view
click_recognizer = NSClickGestureRecognizer.alloc().initWithTarget_action_(self, 'enlarge_text')
self.view.addGestureRecognizer_(click_recognizer)



def update_score(self):
# retrieve the live score from the cricbuzz website
response = requests.get('https://m.cricbuzz.com/')
soup = BeautifulSoup(response.content, 'html.parser')
match_element = soup.find(class_="cbz-ui-home-scores cbz-common-match")
score_text = match_element.text
print(match_element.text)

# create an attributed string with the score text and the desired attributes
font_size = 14.0
font = NSFont.menuFontOfSize_(font_size)
attributes = {
NSFontAttributeName: font,
NSForegroundColorAttributeName: NSColor.whiteColor()
}
score_attributed_text = NSAttributedString.alloc().initWithString_attributes_(score_text, attributes)

# calculate the size of the attributed string
size = score_attributed_text.size()

# scale the font size to fit the available space in the custom view
max_width = self.view.frame().size.width
while size.width > max_width:
font_size = font_size - 1.0
if font_size <= 0:
break
font = NSFont.menuFontOfSize_(font_size)
attributes[NSFontAttributeName] = font
score_attributed_text = NSAttributedString.alloc().initWithString_attributes_(score_text, attributes)
size = score_attributed_text.size()

# update the score in the custom view
score_label = NSTextField.alloc().initWithFrame_(NSMakeRect(0, 0, size.width, size.height))
score_label.setAttributedStringValue_(score_attributed_text)
score_label.setBezeled_(False)
score_label.setEditable_(False)
score_label.setDrawsBackground_(False)
score_label.setAlignment_(NSTextAlignmentCenter)
score_label.setTextColor_(NSColor.whiteColor())
self.view.setSubviews_([score_label])


def enlarge_text(self):
# retrieve the score label from the custom view
score_label = self.view.subviews()[0]

# increase the font size of the label by 2 points
font = score_label.font()
font_size = font.pointSize() + 2.0
font = NSFont.systemFontOfSize_(font_size)
score_label.setFont_(font)


def mouseDown_(self, event):
# enlarge the text in the custom view
self.enlarge_text()

def main():
app = NSApplication.sharedApplication()
delegate = StatusItem.alloc().init()
app.setDelegate_(delegate)
NSApp.activateIgnoringOtherApps_(True)
app.run()






if __name__ == '__main__':
app = NSApplication.sharedApplication()
delegate = StatusItem.alloc().init()
app.setDelegate_(delegate)
NSApp.activateIgnoringOtherApps_(True)
app.run()