コード例 #1
0
class MusicGramTelegramClient:
    def __init__(self,
                 api_id: str,
                 api_hash: str,
                 regenerate_db: bool = False):
        self.id = api_id
        self.hash = api_hash
        self._client: TelegramClient = None

    @property
    def client(self) -> TelegramClient:
        self._client = TelegramClient("musicgram", self.id, self.hash)
        return self._client

    def update_profile_photo(self,
                             client: TelegramClient,
                             file: BytesIO = None,
                             initial_photo_len: int = 0) -> None:
        try:
            pictures = client.get_profile_photos("me")
            if file:
                client(
                    UploadProfilePhotoRequest(file=client.upload_file(
                        file=file, file_name="cover.jpg")))
            if pictures.total > initial_photo_len:
                client(DeletePhotosRequest([pictures[0]]))

        except FloodWaitError as exception:
            LOGGER.INFO(
                f"UploadProfilePhotoRequest flood error pausing for {exception.seconds} seconds!"
            )
            time.sleep(exception.seconds)

    def update_profile_last_name(self,
                                 client: TelegramClient,
                                 last_name: Union[str, None] = None) -> None:
        try:
            client(UpdateProfileRequest(last_name=last_name))
        except FloodWaitError as exception:
            LOGGER.INFO(
                f"UpdateProfileRequest flood error pausing for {exception.seconds} seconds!"
            )
            time.sleep(exception.seconds)

    def save_profile(self):
        if self._client is not None:
            db = DataBase(self._client)
            me = self._client.get_me()
            last_name = me.last_name or ""
            profile_pics = len(self._client.get_profile_photos("me"))
            data = db.generate((last_name, profile_pics))
            db.save()
            return data
コード例 #2
0
    def update_profile_photo(self,
                             client: TelegramClient,
                             file: BytesIO = None,
                             initial_photo_len: int = 0) -> None:
        try:
            pictures = client.get_profile_photos("me")
            if file:
                client(
                    UploadProfilePhotoRequest(file=client.upload_file(
                        file=file, file_name="cover.jpg")))
            if pictures.total > initial_photo_len:
                client(DeletePhotosRequest([pictures[0]]))

        except FloodWaitError as exception:
            LOGGER.INFO(
                f"UploadProfilePhotoRequest flood error pausing for {exception.seconds} seconds!"
            )
            time.sleep(exception.seconds)
コード例 #3
0
ファイル: main.py プロジェクト: glotovdi/teleg-upd-photo
def main():
    parser = ArgumentParser()
    set_arguments(parser)
    args = parser.parse_args()


    client = TelegramClient("tele_session", args.api_id, args.api_hash)
    client.start()

    prev_update_time = ""

    while True:
        if time_has_changed(prev_update_time):
            generate_and_save_quote()
            prev_update_time = convert_time_to_string(datetime.now())
            # client(DeletePhotosRequest(client.get_profile_photos('me')))
            client(DeletePhotosRequest(client.get_profile_photos('me', limit=1)))
            path_to_file = os.getcwd() + f"/src/quote_images/new_quote.jpg"
            file = client.upload_file(path_to_file)
            client(UploadProfilePhotoRequest(file))
        time.sleep(1)
コード例 #4
0
sleep_time = 15 * 60

client_name = 'hamid'
API_ID = 1524689
API_HASH = '14d226885030df209468c3fe12979672'

client = TelegramClient(client_name, API_ID, API_HASH)

client.start()

prevNum = 0

while True:
    # clear current photo
    pics = client.get_profile_photos('me')

    if len(pics) != 0:
        pic = pics[0]

        client(
            DeletePhotosRequest(id=[
                InputPhoto(id=pic.id,
                           access_hash=pic.access_hash,
                           file_reference=pic.file_reference)
            ]))

    # get new random number
    newNum = random.randrange(1, 33)

    # prevent repetetive pics
コード例 #5
0
    font = ImageFont.truetype(font='font.otf', size=235)
    wt, ht = draw.textsize(time, font=font)
    draw.text(((W - wt) / 1.9, (H - ht - 60) / 2),
              time,
              font=font,
              fill='#ffffff')

    font = ImageFont.truetype(font='font.otf', size=50)
    draw.text((W / 7, H / 4.6),
              f"Температура: {temp}°C",
              font=font,
              fill='#ffffff')

    font = ImageFont.truetype(font='font.otf', size=78)
    draw.text((W / 4, H / 1.6), date, font=font, fill='#ffffff')

    font = ImageFont.truetype(font='font.otf', size=50)
    draw.text((W / 2.4, H / 1.17), "NICK", font=font, fill='#ffffff')
    img.save('now.jpg')


while True:  # Delete/Upload image
    if not now_time == get_time():
        current_time = get_time()
        now_time = current_time
        get_image(current_time, get_date(), get_temp())
        image = client.upload_file('now.jpg')
        client(DeletePhotosRequest(client.get_profile_photos('me')))
        client(UploadProfilePhotoRequest(image))